天天看點

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;
        }
    }
    }
               
  • 未完待續(近期工作任務比較多,慢慢更新)

繼續閱讀