Ios-finger Press to reach, how to integrate the 3D Touch in the iOS9

Source: Internet
Author: User
<span id="Label3"></p><span style="background-color: #ccffcc;"><span style="background-color: #ccffcc;">1. Preface</span></span>With the advent of 6S, 3DTouch by the popularity of popular apps, Bo Master personally experience, found that the use of convenience greatly improved, followed by their own documents, wrote a demo out, to share to everyone, hope to have the need for a friend to provide some help.<span style="background-color: #ccffcc;"><span style="background-color: #ccffcc;">2. How do I use 3D Touch? </span></span><span style="background-color: #99ccff;"><span style="background-color: #99ccff;">2.1. The main interface re-press the app icon to pop up the touch menu</span></span><p><p><span style="background-color: #99ccff;"></span></p></p><p><p><span style="background-color: #ffffff; color: #000000;">The <code>AppleDelegate</code> program entry in the file is Configured:</span></p></p><p><p><span style="background-color: #ffffff;"><strong>Didfinishlaunchingwithoptions</strong></span></p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;"> Add 3D Touch menu to App icon/ /take photo //menu icon Uiapplicationshortcuticon *iconcamera = [uiapplicationshortcuticon iconwithtype:uiapplicationshortcuticontypeadd]; Menu Text uimutableapplicationshortcutitem *itemcamera = [[uimutableapplicationshortcutitem alloc] initWithType:@ " 1 "localizedtitle:@" photo "]; Binding information to the specified menu itemcamera.icon = iconcamera; Album //menu icon uiapplicationshortcuticon *iconphotolibrary = [uiapplicationshortcuticon iconwithtype: uiapplicationshortcuticontypesearch]; Menu Text uimutableapplicationshortcutitem *itemphotolibrary = [[uimutableapplicationshortcutitem alloc] initwithtype:@ "2" localizedtitle:@ "album"; Binding information to the specified menu itemphotolibrary.icon = iconphotolibrary; Bind to App icon application.shortcutitems = @[itemcamera,itemphotolibrary];</pre></pre><p><p>Popup menu, We need to let the user click to jump to specify the page</p></p><p><p>Here we'll use a new addition to the Appdelegate.</p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">-(void) application: (uiapplication *) application performactionforshortcutitem: (nonnull uiapplicationshortcutitem *) Shortcutitem completionhandler: (nonnull void (^) (BOOL)) completionhandler;</pre></pre><p><p>Let's do the jump operation in this method.</p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;"> Photo type If ([shortcutitem.type isequaltostring:@ "1"]) { uiimagepickercontroller *picker = [[ Uiimagepickercontroller alloc] init];//initialize picker.allowsediting = yes;//settings editable Picker.sourcetype = uiimagepickercontrollersourcetypecamera; [self.window.rootViewController presentviewcontroller:picker animated:yes completion:nil];//enter The camera interface } // Album Type if ([shortcutitem.type isequaltostring:@ "2"]) { uiimagepickercontroller *picker = [[ Uiimagepickercontroller alloc] init];//initialize picker.allowsediting = yes;//settings editable Picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary; [self.window.rootViewController presentviewcontroller:picker animated:yes completion:nil];//into Photo Gallery</pre></pre><p><p>The camera and album will be accessed after clicking</p></p><p><p></p></p><p><p></p></p><span style="background-color: #99ccff;"><span style="background-color: #99ccff;">2.2.3DTouch Tap the preview feature to add the bottom menu when previewing</span></span><span style="text-decoration: underline; color: #ff0000;"><span style="text-decoration: underline; color: #ff0000;"><strong>first we need to distinguish between a <span style="color: #0000ff; text-decoration: underline;">tap preview</span> and a <span style="color: #0000ff; text-decoration: underline;">long-press gesture</span> , where a basic test is done at Initialization. </strong></span></span> <pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">Nterface viewcontroller () <uiviewcontrollerpreviewingdelegate>{ uilongpressgesturerecognizer *_ longpress;} @end @implementation viewcontroller-(void) viewdidload { [super viewdidload]; Uilongpressgesturerecognizer *LONGPRESSGR = [[uilongpressgesturerecognizer alloc] initwithtarget:self action:@ Selector (longpresstodo)]; _longpress = longpressgr;} Detects if the page is in 3dtouch-(void) check3dtouch{ if (self.traitCollection.forceTouchCapability = = Uiforcetouchcapabilityavailable) { [self registerforpreviewingwithdelegate:self sourceView:self.view]; NSLog (@ "3D Touch on"); Long press Stop _longpress.enabled = NO; } else{ _longpress.enabled = YES; } } -(void) viewwillappear: (BOOL) animated{ [self check3dtouch]; }</pre></pre><p><p></p></p><p><p><span style="background-color: #ffffff;"><strong>Then we need to implement the <span style="text-decoration: underline;">uiviewcontrollerpreviewingdelegate</span> Protocol.</strong></span></p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">@interface Viewcontroller () <UIViewControllerPreviewingDelegate></pre></pre><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">Then implement the proxy Method-(uiviewcontroller *) previewingcontext: (id<uiviewcontrollerpreviewing>) previewingcontext Viewcontrollerforlocation: (cgpoint) location;</pre></pre><p><p></p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">#pragma mark >> 3D touch proxy method//tap into the floating preview Page-(uiviewcontroller *) previewingcontext: (id< uiviewcontrollerpreviewing>) previewingcontext viewcontrollerforlocation: (cgpoint) location{ //note Here I am because of the test, No specific location processing, if you need to locate the specific image cell location, you can use the TableView convertpoint to take the designated cell aspreviewviewcontroller *VC = [[ Aspreviewviewcontroller alloc] init]; Vc.view.frame = self.view.frame; Uiimageview *er = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "123.png"]; Vc.view = er; return vc; }</pre></pre><p><p></p></p><p><p>When you are done, you can achieve a basic preview effect:</p></p><p><p></p></p><p><p></p></p><p><p>finally, we add a</p></p><strong><strong><span style="text-decoration: underline;">Slide the bottom menu to add when previewing</span></strong></strong><p><p>Implement Uiviewcontrollerpreviewingdelegate protocol in the preview controller Aspreviewviewcontroller we just created</p></p><p><p>Then override its Proxy method</p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">-(nsarray<id<uipreviewactionitem>> *) previewactionitems;</pre></pre><p><p></p></p><pre class="brush:csharp;gutter:true;"><pre class="brush:csharp;gutter:true;">Preview page Bottom Action items-(nsarray<id<uipreviewactionitem>> *) previewactionitems{ uipreviewaction *p1 = [uipreviewaction actionwithtitle:@ "share" style:uipreviewactionstyledefault handler:^ (uipreviewaction * _Nonnull action , Uiviewcontroller * _nonnull previewviewcontroller) { NSLog (@ "click to share"); }]; Uipreviewaction *p2 =[uipreviewaction actionwithtitle:@ "collection" style:uipreviewactionstyledefault handler:^ ( Uipreviewaction * _nonnull action, uiviewcontroller * _nonnull previewviewcontroller) { NSLog (@ "click on favorites"); }]; Nsarray *actions = @[p1,p2]; Return actions;}</pre></pre><p><p></p></p><p><p></p></p><span style="color: #ff0000;"><span style="color: #ff0000;"></span></span><span style="color: #008000;"><span style="color: #008000;">Clear Saup</span></span><br><span style="color: #ff0000;"><span style="color: #ff0000;">source:</span></span><span style="color: #008000;"><span style="color: #008000;"> <span style="color: #008000;"> </span> <span style="color: #008000;">http://www.cnblogs.com/qingche/</span> </span></span><br><span style="color: #0000ff;"><span style="color: #0000ff;">This article is copyright to the author and the blog Park is shared, welcome reprint, but must retain this paragraph statement, and in the article page obvious location to give the original text Connection. </span></span><p><p></p></p><p><p>Ios-finger Press to reach, how to integrate the 3D Touch in the iOS9</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.