IOS9 3DTouch (2)--pop/peek

Source: Internet
Author: User

2. In the app, select a content, you can use PEEK (TAP) to preview or use Pop (re-press) switch controller, ians full content

Peek: Tap, preview. 3 different states:

Peek is available, and the other is blurred by the middle grid.

Peek, you can quickly preview the next controller content

Peek+previewaction, quick action

Pop: Generally navigate to the controller previewed in Peek State.

(1) if Forcetouch is available, register

-(void)viewdidload{

[Super Viewdidload];

//register Forcetouch

if(self. Traitcollection. forcetouchcapability = = uiforcetouchcapabilityavailable) {

[self registerforpreviewingwithdelegate:self sourceview:self. View];

}

}

(2) Set up agent and implement proxy method uiviewcontrollerpreviewingdelegate

  • -(Uiviewcontroller *)previewingcontext:(ID<UIViewControllerPreviewing>) Previewingcontext viewcontrollerforlocation:(cgpoint)location {
  • //Get the cell clicked
  • nsindexpath *indexpath = [self. TableView indexpathforrowatpoint:location];
  • UITableViewCell *cell = [self. TableView cellforrowatindexpath:indexpath];
  • if (! Cell) {
  • return nil;
  • }
  • //pre-peek State, highlighted area
  • Previewingcontext. Sourcerect = cell. Frame;
  • hcviewcontroller *vc = [[Hcviewcontroller alloc] init];
  • VC. LabelText = self . DataList[indexpath. Row];
  • //peek Status, the view size displayed
  • VC. Preferredcontentsize = cgsizemake (0, 0);
  • return VC;
  • }
  • - (void)previewingcontext:(ID <UIViewControllerPreviewing>) Previewingcontext commitviewcontroller:(uiviewcontroller *)viewcontrollertocommit
  • {
  • [self. Navigationcontroller pushviewcontroller:viewcontrollertocommit animated:YES];
  • }

(3) P the realization of previewaction in EEK

new arrays, storing previewaction

@property (nonatomic,strong) nsarray *arraypreviewactions;

Returns an array of stored previewaction in the Previewactionitems method;

    • -(nsarray<ID<UIPreviewActionItem>> *)previewactionitems
    • {
    • return self . Arraypreviewactions;
    • }

Sets the contents of the Previewaction array and implements the function. (i.e. quick action)

  • -(void)viewdidload{
  • [Super Viewdidload];
  • self. View. BackgroundColor = [uicolor whitecolor];
  • [Self label];
  • //Set previewactions
  • self. Arraypreviewactions = @[
  •                             [uipreviewaction Actionwithtitle:@< Span class= "S8" > "OK" Style:uipreviewactionstyledefault handler :^ (Uipreviewaction * _ Nonnull Action, uiviewcontroller * _nonnull Previewviewcontroller {
  • NSLog (@"Press OK");
  • }],
  •                             [uipreviewaction Actionwithtitle:@< Span class= "S8" > "Cancel" Style:uipreviewactionstyledestructive Handler:^ (Uipreviewaction * _nonnull Action, uiviewcontroller * _nonnull Previewviewcontroller) {
  • NSLog (@"Press Cancel");
  • }],
  • ];
  • }

IOS9 3DTouch (2)--pop/peek

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.