728x90
3D터치를 하기위해 View에 3d터치 등록.
*.m viewDidLoad
if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
[self registerForPreviewingWithDelegate:self sourceView:self.image1];
[self registerForPreviewingWithDelegate:self sourceView:self.image2];
}
else {
NSLog(@"ForceTouch not available. use LongPress...");
}
Head파일에 Delegate 등록.
@interface ViewController : UIViewController <UIViewControllerPreviewingDelegate>
픽을 했을때의 델리게이트.
- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
DetailImageViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailImageView"];
vc.preferredContentSize = CGSizeMake(0, 300);
vc._delegate = self;
if(previewingContext.sourceView.tag == 1) {
vc.imageTag = 1;
}else if(previewingContext.sourceView.tag == 2) {
vc.imageTag = 2;
}
previewingContext.sourceRect = CGRectMake(0, 0, previewingContext.sourceView.frame.size.width, previewingContext.sourceView.frame.size.height);
return vc;
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
[self presentViewController:viewControllerToCommit animated:YES completion:nil];
}
포스터치를 했을때, 보이는 메뉴 설정.
DetailImageViewController.m
//add previewActionItem
- (NSArray <id <UIPreviewActionItem>> *)previewActionItems
{
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Soccer" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[self._delegate callParentControll:TRUE];
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"BasketBall" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[self._delegate callParentControll:FALSE];
}];
UIPreviewAction *action3_1 = [UIPreviewAction actionWithTitle:@"BaseBall" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[self._delegate callParentControll:FALSE];
}];
UIPreviewAction *action3_2 = [UIPreviewAction actionWithTitle:@"VolleyBall" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[self._delegate callParentControll:FALSE];
}];
UIPreviewActionGroup *action3 = [UIPreviewActionGroup actionGroupWithTitle:@"More" style:UIPreviewActionStyleDestructive actions:@[action3_1, action3_2]];
return @[action1, action2, action3];
}
ForceTouch 강도 체크.
Source
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *t = touches.anyObject;
NSLog(@"touchesBegan : %f / %f", t.force, t.maximumPossibleForce);
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *t = touches.anyObject;
NSLog(@"touchesMoved : %f / %f", t.force, t.maximumPossibleForce);
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *t = touches.anyObject;
NSLog(@"touchesEnded : %f / %f", t.force, t.maximumPossibleForce);
}
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *t = touches.anyObject;
NSLog(@"touchesCancelled : %f / %f", t.force, t.maximumPossibleForce);
}
728x90
'Developer > iOS' 카테고리의 다른 글
[iOS]앱 설정 띄우기 (0) | 2015.12.17 |
---|---|
[iOS]제너릭(Generics) (0) | 2015.12.16 |
[iOS9] ShotCutItem (QuickAction) 퀵액션 추가하기 (0) | 2015.12.03 |
[iOS]Custom Keyboard 아이폰 커스텀 키보드 (0) | 2015.12.02 |
[iOS]홈에서 돌아왔을때, 함수 실행하기 (0) | 2015.10.26 |