天天看点

iOS之旅--iOS11的一些适配工作

  • 跳转App Store评论
- (void)gotoAppStoreEvaluate
{
//1028355284是我们APP的appID,替换成你的应用的appID即可
    NSString *itunesUrl = @"itms-apps://itunes.apple.com/cn/app/id1028355284?mt=8&action=write-review";
    NSURL * url = [NSURL URLWithString:itunesUrl];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication]openURL:url];
    } else {
        NSLog(@"can not open");
    }
}
           
  • UISearchBar的修改

    之前的searchbar高度为44使用,现在iOS11之后,高度是56不能改变(目前没有找到修改高度的办法)。兼容一下在iOS11上搜索框的高度设置为56了。

    NSInteger sbHeight = ;
    if (@available(iOS , *)) {
      sbHeight = ;
    }
               
  • UITableView和UIScrollView的修改
    // tableView 偏移20/适配
    if (@available(iOS , *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
               
  • UIToolBar 在iOS11之后默认添加了_UIToolbarContentView,里面有点击事件,会把自己定义的点击事件拦截。 可以在封装的view里面这样处理。如果代码没有封装全部在控制器里面,有另外一种办法,可以自行百度。
    - (void)layoutSubviews {
    [super layoutSubviews];
    NSArray *subViewArray = [self subviews];
    for (id view in subViewArray) {
        if ([view isKindOfClass:(NSClassFromString(@"_UIToolbarContentView"))]) {
            UIView *testView = view;
            testView.userInteractionEnabled = NO;
        }
    }
    }
               
  • 未完待续(近期工作任务比较多,慢慢更新)

继续阅读