UITableView篇
自定義TableViewCell拖拽事件后,在iOS11上滑動TableView衣式,界面元素會消失俯艰。
解決方法:
if (@available(iOS 11, *)) {
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
}
系統(tǒng)默認的左滑刪除事件中权悟,左滑的距離可以過長的問題,而且當(dāng)你full swipe(完全滑動)的時候陨享,系統(tǒng)會自動執(zhí)行第一個action的handler葱淳。
iOS8之后新增了代理方法tableView: editActionsForRowAtIndexPath:和類UITableViewRowAction,可以在這個代理方法中定義所需要的操作按鈕(刪除抛姑、置頂?shù)?赞厕,這些按鈕的類就是UITableViewRowAction。這個類只能定義按鈕的顯示文字定硝、背景色皿桑、和按鈕事件。
并且返回數(shù)組的第一個元素在UITableViewCell的最右側(cè)顯示蔬啡,最后一個元素在最左側(cè)顯示诲侮。iOS 11可以給這些按鈕添加圖片了,而且如果實現(xiàn)了以下兩個iOS 11新增的代理方法箱蟆,將會取代tableView: editActionsForRowAtIndexPath:代理方法:
- ( UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
//刪除
UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self deleteObject:indexPath];
}];
deleteAction.image = [UIImage imageNamed:@"del"];
deleteAction.backgroundColor = [UIColor redColor];
UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
return config;
}
typedef NS_ENUM(NSInteger, UIContextualActionStyle) {
UIContextualActionStyleNormal,
UIContextualActionStyleDestructive
}
UIContextualActionStyle有兩種類型沟绪,如果是置頂、已讀等按鈕就使UIContextualActionStyleNormal類型空猜,delete操作按鈕可使用UIContextualActionStyleDestructive類型绽慈,當(dāng)使用該類型時,如果是左滑操作辈毯,一直滑動某個cell坝疼,會直接執(zhí)行刪除操作,不用再點擊刪除按鈕漓摩,即系統(tǒng)會自動執(zhí)行第一個action的handler裙士。當(dāng)然了,如果產(chǎn)品需求是必須跟之前風(fēng)格統(tǒng)一只能點“刪除”按鈕才能刪除而且不能左滑距離過長就不能直接這么用了管毙。
解決方法1:
//iOS11及以上
#ifdef __IPHONE_11_0
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){
UIContextualAction *action=[UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"刪除" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
[self deleteRecord:indexPath];
}];
action.backgroundColor = [UIColor redColor];
UISwipeActionsConfiguration *config=[UISwipeActionsConfiguration configurationWithActions:@[action]];
config.performsFirstActionWithFullSwipe = NO;
return config;
}
#endif
解決方法2:
仿微信效果通過pan手勢自定義左滑事件解決腿椎。
詳細代碼見demo:
https://github.com/WSGNSLog/EditTableView
iOS11 無法跳轉(zhuǎn)設(shè)置頁--做到了跳轉(zhuǎn)設(shè)置頁桌硫,但不是指定設(shè)置頁
參照:http://www.reibang.com/p/527c7098add5
判斷ios11 系統(tǒng)的宏這樣寫 不會報警告
#define IOS11 @available(iOS 11.0, *)
//判斷是iPhoneX 的宏
#define is_iPhoneX [UIScreen mainScreen].bounds.size.width == 375.0f && [UIScreen mainScreen].bounds.size.height == 812.0f
keyWindow獲取
iOS 11之前通過 [[UIApplication sharedApplication].windows lastObject]獲取keyWindow沒有問題,iOS11多了一個UIRemoteKeyboardWindow啃炸,改為通過[UIApplication sharedApplication].keyWindow獲取
po [UIApplication sharedApplication].windows
<__NSArrayM 0x1c085f410>(
<UIWindow: 0x103e14170; frame = (0 0; 414 736); autoresize = W+H; gestureRecognizers = <NSArray: 0x1c405ee10>; layer = <UIWindowLayer: 0x1c4039820>>,
<UITextEffectsWindow: 0x1048f7800; frame = (0 0; 414 736); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x1c403ae00>>,
<UIRemoteKeyboardWindow: 0x104100c00; frame = (0 0; 414 736); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x1c04306c0>>
)
iPhone X Push過程中TabBar位置上移
在UINavigationController
的基類重寫pushViewController
代理方法铆隘,在Push的時候修正一下TabBar
的frame
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.viewControllers.count > 0) {
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
// 修改tabBra的frame
CGRect frame = self.tabBarController.tabBar.frame;
frame.origin.y = [UIScreen mainScreen].bounds.size.height - frame.size.height;
self.tabBarController.tabBar.frame = frame;
}
其他跳動問題解決
在繼承于系統(tǒng)UITabBar
的子類加上下面代碼
#import "XYTabBar.h"
@interface XYTabBar()
@property (nonatomic,assign)UIEdgeInsets oldSafeAreaInsets;
@end
@implementation XYTabBar
- (void) safeAreaInsetsDidChange
{
[super safeAreaInsetsDidChange];
if(self.oldSafeAreaInsets.left != self.safeAreaInsets.left ||
self.oldSafeAreaInsets.right != self.safeAreaInsets.right ||
self.oldSafeAreaInsets.top != self.safeAreaInsets.top ||
self.oldSafeAreaInsets.bottom != self.safeAreaInsets.bottom)
{
self.oldSafeAreaInsets = self.safeAreaInsets;
[self invalidateIntrinsicContentSize];
[self.superview setNeedsLayout];
[self.superview layoutSubviews];
}
}
- (CGSize) sizeThatFits:(CGSize) size
{
CGSize s = [super sizeThatFits:size];
if(@available(iOS 11.0, *))
{
CGFloat bottomInset = self.safeAreaInsets.bottom;
if( bottomInset > 0 && s.height < 50) {
s.height += bottomInset;
}
}
return s;
}
@end
參考:http://blog.csdn.net/xuyang844175181/article/details/78134552
Xcode9出現(xiàn)錯誤safe area layout guide before ios 9 真正解決辦法:
正解是選中控制器,右邊面板的Builds for 選擇iOS9.0 and Later南用,如下圖紅框
廣為流傳的錯解是不勾選Use Safe Area Layout Guides膀钠,如下圖灰框,會導(dǎo)致用不了iOS的這個新功能了
UITableView頂部空白
設(shè)置:
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];