iOS 18 tabbar有默認動畫,切換的時候頁面有縮放效果

https://blog.csdn.net/qq_43441647/article/details/143366477ba

//這是自定義tabbar里面的selectedIndex的方法,按其他那個加代理,自己定義動畫的那個方法沒起作用。這個方法可以

- (void)setSelectedIndex:(NSUInteger)selectedIndex{

? ? if(selectedIndex >=self.viewControllers.count){

? ? ? ? @throw [NSException exceptionWithName:@"selectedTabbarError"

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? reason:@"No controller can be used,Because of index beyond the viewControllers,Please check the configuration of tabbar."

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? userInfo:nil];

? ? }


? ? //取掉iOS 18tabbar縮放動畫,如果不去掉,頁面會有縮放效果,先下拉然后恢復

? ? if(@available(iOS18.0, *)) {

? ? ? ? [UIView performWithoutAnimation:^{

? ? ? ? ? ? [supersetSelectedIndex:selectedIndex];

? ? ? ? }];

? ? }else{

? ? ? ? [supersetSelectedIndex:selectedIndex];

? ? }


? ? [self.cyTabbar setValue:[NSNumber numberWithInteger:selectedIndex] forKeyPath:@"selectButtoIndex"];

}



//這中在代理里面自定義切換動畫的方式,寫了不起作用

@interface TabBarController () <UIViewControllerAnimatedTransitioning, UITabBarControllerDelegate>

@end

@implementation TabBarController

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? //設置代理

? ? self.delegate = self;

}

#pragma mark - UITabBarControllerDelegate

- (nullable id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController

? ? ? ? ? ? ? ? ? ? animationControllerForTransitionFromViewController:(UIViewController *)fromVC

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? toViewController:(UIViewController *)toVC {


? ? return self;

}

#pragma mark - UIViewControllerAnimatedTransitioning

- (void)animateTransition:(nonnull id<UIViewControllerContextTransitioning>)transitionContext {

? ? UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];

? ? [transitionContext.containerView addSubview:toView];

? ? [transitionContext completeTransition:YES];

}

//返回0s禁用動畫

- (NSTimeInterval)transitionDuration:(nullable id<UIViewControllerContextTransitioning>)transitionContext {

? ? return 0;

}

@end

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容