ios - UISplitViewController pan to primary view from anywhere -


sorry long-winded explination, question - or similar - has been asked few times , havent found satisfactory answer. writing ipad app in ios 8 implements uisplitviewcontroller. have been attempting work on iphone. transferred on pretty well, collapses automatically , button included in left side of nav. bar.

my problem want keep button functionality pop 1 view off stack, able pan primary view if there several detail views on top of it. ideally, want able overwrite or redirect interactivepopgesturerecognizer gesture smoothly pans primary view (in cases can have anywhere 1 4 detail views stacked on top of it). but, cannot figure out how this.

my current solution (code below) disable interactivepopgesturerecognizer in detail viewcontroller , implement own screenedgepangesturerecognizer that, when triggered, executes poptorootviewcontroller. i've subclassed screenedgepangesturerecognizer treats screen edge pan discrete "swipe" (i.e. once large enough screen edge swipe detected - pop off stack primary view visible).

code in detail view controller stop interactivepopgesturerecognizer:

-(void)viewwillappear : (bool) animated {      [super viewwillappear : animated];     // stops navigation controller responding default swipe gesture     if ([self.navigationcontroller respondstoselector:@selector(interactivepopgesturerecognizer)]) {         self.navigationcontroller.interactivepopgesturerecognizer.enabled =no;         self.navigationcontroller.interactivepopgesturerecognizer.delegate = self;     } }  // disable default swipe gesture tied automatically included button -(bool)gesturerecognizershouldbegin:(uigesturerecognizer *)gesturerecognizer {      if ([gesturerecognizer isequal:self.navigationcontroller.interactivepopgesturerecognizer]) {         return no;     } else {         return yes;             }  } 

i didn't think necessary include subclass screenedgepangesturerecognizer because has nothing solution asking here pseudocode shows @selector in detail viewcontroller:

- (ibaction)leftedgeswipe:(screenedgeswipegesturerecognizer*)sender {     if (sender.swipeisvalid) {         [(uinavigationcontroller *)self.splitviewcontroller.viewcontrollers[0]          poptorootviewcontrolleranimated:yes];     } } 

i tried use continuous pan, cannot find way present primary view in background pulling current view aside give clean, smooth panning effect. able make can move current view around, there grey background behind want primary view be.

summation: if there indeed no way change interactivepopgesturerecognizer jump primary view (ideal solution), info on how can make own smooth pan primary view appreciated.

so have been messing around making smooth panning gesture subclass. functions apple's gesture except jumps way root view controller instead of popping 1 view off stack. problem not yet show primary view in background while panning. update answer once worked out.

here subclass:

#import <uikit/uikit.h> #import <uikit/uigesturerecognizersubclass.h> #import "screenedgeswipegesturerecognizer.h"    @interface screenedgeswipegesturerecognizer ()  @property (nonatomic) uinavigationcontroller* navcontroller;  @end   @implementation screenedgeswipegesturerecognizer{     cgpoint _screencenter;     cgpoint _cumulativepandistance; }    - (id)initwithnavigationcontroller:(uinavigationcontroller*)navcontroller {     self = [super initwithtarget:self action:@selector(leftedgepan:)];     _screencenter = cgpointzero;     _cumulativepandistance = cgpointzero;     self.edges = uirectedgeleft;     self.navcontroller = navcontroller;     return self; }    - (ibaction)leftedgepan:(screenedgeswipegesturerecognizer*)sender {     assert(sender == self);      switch (self.state) {         case uigesturerecognizerstatebegan:             [self initializepositions];             break;          case uigesturerecognizerstatechanged:             [self updatepositions];             break;          case uigesturerecognizerstateended:             [self animateviewbasedoncurrentlocation];             break;          case uigesturerecognizerstatecancelled:             [self animateviewtocenter];             break;          default:             break;     }      // reset velocity of pan current velocity not compound velocity of next cycle     [sender settranslation:cgpointmake(0, 0) inview:sender.view]; }    - (void)initializepositions {     _screencenter = self.view.center;     _cumulativepandistance = cgpointzero; }    - (void)updatepositions {     // track position of user touch event     cgpoint deltasincelastcycle = [self translationinview:self.view];      // view center = view center @ last cycle + distance moved user touch since last cycle     self.view.center=cgpointmake((self.view.center.x +   deltasincelastcycle.x), self.view.center.y+ 0);      // update total positive distance traveled user touch event.     _cumulativepandistance.x = _cumulativepandistance.x + deltasincelastcycle.x; }    - (void)animateviewbasedoncurrentlocation {     if (_cumulativepandistance.x >= (_screencenter.x - 50)){         [self reset];         [_navcontroller poptorootviewcontrolleranimated:yes];     }else{         [self animateviewtocenter];         [self reset];     } }    - (void)animateviewtocenter {     [uiview animatewithduration:0.25 animations:^{self.view.center = self->_screencenter;}]; }    - (void)reset {     [super reset];     _cumulativepandistance = cgpointzero;     self.state = uigesturerecognizerstatepossible; }  @end 

here how instantiate recognizer in view controller:

- (void)viewdidappear:(bool)animated {     [super viewdidappear:animated];      // initialize screen edge pan gesture recognizer.     _masternavigationcontroller = self.splitviewcontroller.viewcontrollers[0];      screenedgepangesturerecognizer* edgepanrecognizer =  [[screenedgeswipegesturerecognizer alloc] initwithnavigationcontroller:_masternavigationcontroller];      // add recognizer view controller bound to.     [self.view addgesturerecognizer:_edgepanrecognizer]; } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -