iOS11适配问题总结

一、tableview 留空

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
self = [super initWithFrame:frame style:style];
if (self) {
self.estimatedRowHeight = 0;
self.estimatedSectionHeaderHeight = 0;
self.estimatedSectionFooterHeight = 0;
}
return self;
}

二、导航栏返回按钮

1
2
3
4
5
6
7
8
UIImage *backButtonImage = [[UIImage imageNamed:@"arrow_back_gray"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)
resizingMode:UIImageResizingModeTile];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.backIndicatorImage = [UIImage imageNamed:@"arrow_back_gray"];
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"arrow_back_gray"];

三、判断11

1
2
3
4
5
if (@available(iOS 11.0, *)) {
} else {
}
1
2
3
4
5
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
#eles
#endif

四、键盘默认大写不起作用 (待解决)

_carTextField.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;//所有字母大写

五、左滑删除崩溃问题

使用 MGSwipeTableCell

你的cell 继承MGSwipeTableCell

1
cell.delegate = self;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma mark Swipe Delegate
-(BOOL) swipeTableCell:(MGSwipeTableCell*) cell canSwipe:(MGSwipeDirection) direction;
{
return YES;
}
-(NSArray*) swipeTableCell:(MGSwipeTableCell*) cell swipeButtonsForDirection:(MGSwipeDirection)direction
swipeSettings:(MGSwipeSettings*) swipeSettings expansionSettings:(MGSwipeExpansionSettings*) expansionSettings
{
swipeSettings.transition = MGSwipeTransitionBorder;
expansionSettings.buttonIndex = 0;
__weak BHAllMessageVC * me = self;
BHMessageModel *model = [me mailForIndexPath:[self.allMessageTableView indexPathForCell:cell]];
if (direction == MGSwipeDirectionLeftToRight) {
return nil;
}else{
expansionSettings.fillOnTrigger = YES;
expansionSettings.threshold = 1.1;
CGFloat padding = 15;
MGSwipeButton * trash = [MGSwipeButton buttonWithTitle:@"删除" backgroundColor:[UIColor colorWithRed:1.0 green:59/255.0 blue:50/255.0 alpha:1.0] padding:padding callback:^BOOL(MGSwipeTableCell *sender) {
NSIndexPath * indexPath = [me.allMessageTableView indexPathForCell:sender];
[me deleteMail:indexPath addModel:model];
[cell hideSwipeAnimated:YES];
return NO; //don't autohide to improve delete animation
}];
return @[trash];
}
}
-(BHMessageModel *) mailForIndexPath:(NSIndexPath*) path
{
return [self.allMessageData objectAtIndex:path.section];
}
-(void) deleteMail:(NSIndexPath *) indexPath addModel:(BHMessageModel*)model
{
[self.allMessageData removeObjectAtIndex:indexPath.section];
[self.allMessageTableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[self.allMessageTableView endUpdates];
[[BHQuoteManager manager] PostDeleteMessageByMesasgeId:model.messageId Sucess:^(NSMutableDictionary *dicData) {
NSLog(@"%@",dicData);
} failure:^(NSError *error) {
NSLog(@"%@",error);
BHAlert(@"", @"删除消息失败");
}];
}
-(void) swipeTableCell:(MGSwipeTableCell*) cell didChangeSwipeState:(MGSwipeState)state gestureIsActive:(BOOL)gestureIsActive
{
NSString * str;
switch (state) {
case MGSwipeStateNone: str = @"None"; break;
case MGSwipeStateSwippingLeftToRight: str = @"SwippingLeftToRight"; break;
case MGSwipeStateSwippingRightToLeft: str = @"SwippingRightToLeft"; break;
case MGSwipeStateExpandingLeftToRight: str = @"ExpandingLeftToRight"; break;
case MGSwipeStateExpandingRightToLeft: str = @"ExpandingRightToLeft"; break;
}
NSLog(@"Swipe state: %@ ::: Gesture: %@", str, gestureIsActive ? @"Active" : @"Ended");
}

六、UIScrollView

1
2
3
if (@available(iOS 11.0, *)) {
_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

####七、线程错误

Main Thread Checker: UI API called on a background thread: -[UIApplication applicationState]PID: 37870, TID: 5563145, Thread name: (none), Queue name: com.tencent.bugly.operationQueue (QOS: UTILITY), QoS: 17

正确

1
dispatch_async(dispatch_get_main_queue()

error

1
dispatch_sync(dispatch_get_main_queue()

参考