iOS11之Nav Big Title、UITableView

2017-06-19  本文已影响413人  fengzilai

近期应公司组长要求做个wwdc17的分享,顺便记录一下。

Nav Large Titles                大导航栏

UITableView Swipe Api  左右滑动新API

1.Nav Large Titles

设置是否为大导航栏的属性:

@property (nonatomic, readwrite, assign) BOOL prefersLargeTitles;  //Defaults to NO.

self.navigationController.navigationBar.prefersLargeTitles = true;

为大导航栏时,(prefersLargeTitles = true)时大导航栏显示样式:

通过这个可以控制不同需求的导航栏样式

3个枚举值

@property (nonatomic, readwrite, assign) UINavigationItemLargeTitleDisplayMode largeTitleDisplayMode;

self.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;

typedef NS_ENUM(NSInteger, UINavigationItemLargeTitleDisplayMode) {

UINavigationItemLargeTitleDisplayModeAutomatic,

UINavigationItemLargeTitleDisplayModeAlways,

UINavigationItemLargeTitleDisplayModeNever,

}

2.UITableView Swipe Api

iOS新增的UITableViewDelegate 代理方法

构造一个UIContextualAction,与UIAlertAction类似, action回调在block里面。   有UIContextualActionStyleNormal和UIContextualActionStyleDestructive两种样式,还可以设置背景色,标题,图片。

把生成的UIContextualAction放进数组,对的,所以可以有多个左滑动或者右滑动的视图,构造UISwipeActionsConfiguration,返回就行啦

UISwipeActionsConfiguration 有个performsFirstActionWithFullSwipe的属性是指第一个UIContextualAction是否支持是滑动范围很大(整个屏幕时)触发action

//left views

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView  leadingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{

BOOL hasLike = [self.likeArr containsObject:self.list[indexPath.row]];

NSString *title = hasLike ? @"unlike":@"like";

UIContextualAction *action = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:title handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if (hasLike) {

cell.accessoryType = UITableViewCellAccessoryNone;

[self.likeArr removeObject:self.list[indexPath.row]];

}else{

cell.accessoryType = UITableViewCellAccessoryCheckmark;

[self.likeArr addObject:self.list[indexPath.row]];

}

completionHandler(true);

}];

UISwipeActionsConfiguration  *configuration =  [UISwipeActionsConfiguration configurationWithActions:@[action]];

configuration.performsFirstActionWithFullSwipe  = false;

return configuration;

}

//right views

- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath

{

UIContextualAction *action = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {

[self.list removeObjectAtIndex:indexPath.row];

completionHandler(true);

}];

UISwipeActionsConfiguration  *configuration =  [UISwipeActionsConfiguration configurationWithActions:@[action]];

configuration.performsFirstActionWithFullSwipe  = false;

return configuration;

}

rightView leftView
上一篇下一篇

猜你喜欢

热点阅读