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