问题描述
我需要使用Force Touch在Objective C中的 UITableViewCell
上启用 Peek And Pop
功能。并且还需要在默认邮件应用程序的窥视视图下显示一些操作。我是iOS新手,请帮助我到达那里。
I need to enable Peek And Pop
functionality on a UITableViewCell
in Objective C by using Force Touch. And also need to show some actions under peek view like default mail app. I am new to iOS and please help me to get there.
推荐答案
TableViewCell和Collection上的Peek和Pop效果查看具有操作的单元格
1)您应该将调用者viewController类作为UIViewControllerPreviewing代表
@interface MyTableViewController()
@interface MyTableViewController ()
2)创建一个@property来存储信息。
@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)指定视图控制器我们要预览的内容( FOR 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)当控制器看到并向上滑动时,如果你想添加像delete这样的按钮,将这个方法添加到你的previewViewContrller中(在这个例子中是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];
}
这篇关于在UITableViewCell Objective C Code上进行3D Touch Peek和Pop。 (强制触摸)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!