UITableViewCell Objective C 代码上的 3D Touch Peek 和 Pop。 (强制触摸)
3D Touch Peek And Pop on UITableViewCell Objective C Code. (Force Touch)
我需要使用 Force Touch 在 Objective C 中的 UITableViewCell
上启用 Peek And Pop
功能。并且还需要在默认邮件应用程序等速览视图下显示一些操作。我是 iOS 的新手,请帮助我到达那里。
使用操作对 TableViewCell 和集合视图单元格进行查看和弹出效果
1)您应该称呼您的调用者 viewController class 为 UIViewControllerPreviewing Delegate
@interface MyTableViewController()
2)创建一个@属性用于存储信息。
@property (nonatomic, strong) id previewingContext;
3)调用ViewDidLoad中的forceTouchIntialize方法
- (void)viewDidLoad {
[super viewDidLoad];
[self forceTochIntialize];
}
4)检查Force Touch是否可用
-(void)forceTouchIntialize{
if ([self isForceTouchAvailable]) {
self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
- (BOOL)isForceTouchAvailable {
BOOL isForceTouchAvailable = NO;
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]) {
isForceTouchAvailable = self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
}
return isForceTouchAvailable;
}
5)指定视图控制器我们要预览的内容(用于 PEEK)
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing> )previewingContext viewControllerForLocation:(CGPoint)location{
CGPoint cellPostion = [yourTableView convertPoint:location fromView:self.view];
NSIndexPath *path = yourTableView indexPathForRowAtPoint:cellPostion];
if (path) {
UITableViewCell *tableCell = [yourTableView
cellForRowAtIndexPath:path];
//Pushing to a nib File
PushViewController *previewController = [[PushViewController alloc] initWithNibName:@"PushViewController" bundle:nil];
//To Pass data to Preview ViewController
// id temp = [yourDataArray objectAtIndex:path.row];
// PushViewController.anyObject=temp;
previewingContext.sourceRect = [self.view convertRect:tableCell.frame fromView: yourTableView
]; return previewController;
}
return nil;
}
6)深压中的 POP (FOR POP)
-(void)previewingContext:(id )previewingContext commitViewController: (UIViewController *)viewControllerToCommit {
[self.navigationController showViewController:viewControllerToCommit sender:nil];
}
7)当controller get peek 向上滑动时,如果你想添加delete,archive 之类的按钮,将这个方法添加到你的previewViewController(在这个例子中是“PushViewController”)
- (NSArray<id> *)previewActionItems {
UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:@"delete" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
}];
UIPreviewAction *previewAction2 = [UIPreviewAction actionWithTitle:@"archive" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
}];
return @[previewAction1,previewAction2];
}
我需要使用 Force Touch 在 Objective C 中的 UITableViewCell
上启用 Peek And Pop
功能。并且还需要在默认邮件应用程序等速览视图下显示一些操作。我是 iOS 的新手,请帮助我到达那里。
使用操作对 TableViewCell 和集合视图单元格进行查看和弹出效果
1)您应该称呼您的调用者 viewController class 为 UIViewControllerPreviewing Delegate
@interface MyTableViewController()
2)创建一个@属性用于存储信息。
@property (nonatomic, strong) id previewingContext;
3)调用ViewDidLoad中的forceTouchIntialize方法
- (void)viewDidLoad {
[super viewDidLoad];
[self forceTochIntialize];
}
4)检查Force Touch是否可用
-(void)forceTouchIntialize{
if ([self isForceTouchAvailable]) {
self.previewingContext = [self registerForPreviewingWithDelegate:self sourceView:self.view];
}
}
- (BOOL)isForceTouchAvailable {
BOOL isForceTouchAvailable = NO;
if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)]) {
isForceTouchAvailable = self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
}
return isForceTouchAvailable;
}
5)指定视图控制器我们要预览的内容(用于 PEEK)
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing> )previewingContext viewControllerForLocation:(CGPoint)location{
CGPoint cellPostion = [yourTableView convertPoint:location fromView:self.view];
NSIndexPath *path = yourTableView indexPathForRowAtPoint:cellPostion];
if (path) {
UITableViewCell *tableCell = [yourTableView
cellForRowAtIndexPath:path];
//Pushing to a nib File
PushViewController *previewController = [[PushViewController alloc] initWithNibName:@"PushViewController" bundle:nil];
//To Pass data to Preview ViewController
// id temp = [yourDataArray objectAtIndex:path.row];
// PushViewController.anyObject=temp;
previewingContext.sourceRect = [self.view convertRect:tableCell.frame fromView: yourTableView
]; return previewController;
}
return nil;
}
6)深压中的 POP (FOR POP)
-(void)previewingContext:(id )previewingContext commitViewController: (UIViewController *)viewControllerToCommit {
[self.navigationController showViewController:viewControllerToCommit sender:nil];
}
7)当controller get peek 向上滑动时,如果你想添加delete,archive 之类的按钮,将这个方法添加到你的previewViewController(在这个例子中是“PushViewController”)
- (NSArray<id> *)previewActionItems {
UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:@"delete" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
}];
UIPreviewAction *previewAction2 = [UIPreviewAction actionWithTitle:@"archive" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
}];
return @[previewAction1,previewAction2];
}