iOS 15相关改动

2023-06-06  本文已影响0人  woniu

一、导航栏设置

1、导航栏背景颜色

在iOS 13及以上版本中,使用UINavigationBarAppearance类来设置导航栏的样式,而不再使用UINavigationBar的属性。因此,我们需要将样式赋值给navigationBar的standardAppearance和scrollEdgeAppearance属性,以确保导航栏在不同状态下都能够显示正确的样式

// 导航栏背景颜色
UIColor *navBarBgColor = [UIColor colorWithHexString:@"#F6F8FA"];
if (@available(iOS 15.0, *)) {
    UINavigationBarAppearance *apperance = [[UINavigationBarAppearance alloc] init];
    apperance.backgroundColor = navBarBgColor;
    self.navigationBar.standardAppearance = apperance;
    self.navigationBar.scrollEdgeAppearance = apperance;
} else {
    self.navigationBar.barTintColor = navBarBgColor;
}

2、导航栏文本样式

之所以适配版本是15,是因为在iOS 13UINavigationBar新增了scrollEdgeAppearance属性,但在iOS 14及更早的版本中此属性只应用在大标题导航栏上。在iOS 15中此属性适用于所有导航栏。

// 导航栏标题文本样式
NSDictionary *titleStyle = @{
    NSForegroundColorAttributeName: [UIColor blackColor],
    NSFontAttributeName: [UIFont fontWithName:FontMedium size:19]
};
if (@available(iOS 15.0, *)) {
    UINavigationBarAppearance *apperance = [[UINavigationBarAppearance alloc]init];
    [apperance setTitleTextAttributes: titleStyle];
    self.navigationBar.standardAppearance = apperance;
    self.navigationBar.scrollEdgeAppearance = apperance;
} else {
    self.navigationBar.titleTextAttributes = titleStyle;
}
``

####3、导航栏控件颜色:
self.navigationBar.tintColor = UIColor.redColor;

二、Tabbar按钮动效
通过tabBar: didSelectItem:代理方法接收每次点击的item,对每个item都绑定动画效果,获取到的是item里面的UITabBarSwappableImageView图片对象。

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{

}

// 添加tabbar点击动画
- (void)animationWithIndex:(NSInteger) index {
    NSMutableArray * tabbarbuttonArray = [NSMutableArray array];
    for (UIView *tabBarButton in self.customTabBar.subviews) {
        if ([tabBarButton isKindOfClass:NSClassFromString(@"TYTGCarTabButton")]) {
            [tabbarbuttonArray addObject:tabBarButton];
        }
    }
    CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pulse.duration = 0.2;
    pulse.repeatCount= 1;
    pulse.autoreverses= YES;
    pulse.fromValue= [NSNumber numberWithFloat:0.9];
    pulse.toValue= [NSNumber numberWithFloat:1.1];
    UIView *TabBarButton = tabbarbuttonArray[index];
    [TabBarButton.layer addAnimation:pulse forKey:nil];
}

具体方案:https://www.codenong.com/jsbfa4ac38eadd/

上一篇 下一篇

猜你喜欢

热点阅读