點(diǎn)擊app icon 顯示3D顯示效果
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//動(dòng)態(tài)添加 3Dtouch
self.window = [UIWindow new];
self.window.backgroundColor = [UIColor whiteColor];
self.window.frame = [[UIScreen mainScreen] bounds];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[ViewController new]];
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc] initWithType:@"one" localizedTitle:@"Little" localizedSubtitle:@"王先森" icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay] userInfo:nil];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"boss_red_dot"];
UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc] initWithType:@"two" localizedTitle:@"Daddy" localizedSubtitle:@"575385842@qq.com" icon:icon2 userInfo:nil];
[UIApplication sharedApplication].shortcutItems = @[item1, item2];
return YES;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
//對(duì)應(yīng)的 3D 添加 效果
UINavigationController *navi = (UINavigationController *)self.window.rootViewController;
ViewController *vc = [[ViewController alloc] init];
if ([shortcutItem.type isEqualToString:@"one"]) {
vc.title = @"One";
vc.view.backgroundColor = [UIColor greenColor];
} else if ([shortcutItem.type isEqualToString:@"two"]) {
vc.title = @"Two";
vc.view.backgroundColor = [UIColor orangeColor];
}
[navi pushViewController:vc animated:YES];
}
- 通過(guò)獲取
shortcutItem.type
來(lái)確定用戶的選中
點(diǎn)擊UIView觸發(fā)Touch
- (BOOL)check3DTouch{
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
return YES;
} else {
return NO;
}
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
if ([self check3DTouch]) {
UITouch *touch = [touches anyObject];
self.backgroundColor = [UIColor colorWithRed:touch.force / touch.maximumPossibleForce green:0.0f blue:0.0f alpha:1.0f];
} else {
NSLog(@"CAN NOT USE 3D TOUCH!");
}
}
touch.force
對(duì)應(yīng)的是touch 的力度姑尺,touch.maximumPossibleForce
可感應(yīng)的最大力度。
check3DTouch
判斷當(dāng)前的設(shè)備支持3d touch功能與否。
Touch 點(diǎn)擊單獨(dú)的一個(gè)UIView刊殉,想去讓這個(gè)UIView里面的子控件做出反應(yīng),例UITableVIew 中的cell
_tableview
一個(gè)繼承UITableView通過(guò)點(diǎn)擊cell觸發(fā)touch效果
- 當(dāng)前控制器遵守UIViewControllerPreviewingDelegate協(xié)議。實(shí)現(xiàn)里面的peek(touch下顯示view)舰蟆、pop(touch進(jìn)入vc)方法贮缕。
//peek
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
if ([self.presentedViewController isKindOfClass:[ViewController class]]) {
//已經(jīng)推出 過(guò)了 就 不要再去 使用這個(gè) 代理了
return nil;
} else {
// ViewController *vc = [[ViewController alloc] init];
// vc.title = @"previewVC";
// vc.view.backgroundColor = [UIColor cyanColor];
location = [self.view convertPoint:location toView:_tableview];
NSIndexPath *indexPath = [_tableview indexPathForRowAtPoint:location];
ViewController *displayVC = [[ViewController alloc] init];
displayVC.title = [_tableview cellForRowAtIndexPath:indexPath].textLabel.text;
displayVC.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 256.0
green:arc4random() % 256 / 256.0
blue:arc4random() % 256 / 256.0
alpha:1.0];
// peek預(yù)覽窗口大小
displayVC.preferredContentSize = CGSizeMake(0.0, 100 * indexPath.row);
// 進(jìn)入peek前不被虛化的rect
previewingContext.sourceRect = [self.view convertRect:[_tableview cellForRowAtIndexPath:indexPath].frame fromView:_tableview];
return displayVC;
}
}
//pop
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self showViewController:viewControllerToCommit sender:self];
}
location = [self.view convertPoint:location toView:_tableview];
- 點(diǎn)擊self.view 的點(diǎn)處在_tableview中的位置
NSIndexPath *indexPath = [_tableview indexPathForRowAtPoint:location];
- 獲取點(diǎn)擊的cell下標(biāo)
peek 提示框
//peek 提示框
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems {
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Little" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"點(diǎn)擊執(zhí)行的操作");
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Daddy" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
}];
NSArray *actions = @[action1, action2];
UIPreviewActionGroup *group = [UIPreviewActionGroup actionGroupWithTitle:@"多組按鈕" style:UIPreviewActionStyleDefault actions:actions];
UIPreviewAction *action4 = [UIPreviewAction actionWithTitle:@"單組按鈕" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
}];
NSArray *array = @[group, action4];
return array;
}