objective c - Slide up UIView following finger similar to Control Center in iOS -
i have uitableview @ bottom of main uiviewcontroller, shows top 2 rows. show rest don't want scroll, want user able "pull" view reveal additional 4 rows (can swipe down on "push" original place), , want "pull" similar how control center works in ios. spring has great.
looks can add uipangesturerecognizer pull:
uipangesturerecognizer * pan = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pan:)]; pan.maximumnumberoftouches = pan.minimumnumberoftouches = 1; [self addgesturerecognizer:pan]; - (void)pan:(uipangesturerecognizer *)apan; { cgpoint currentpoint = [apan locationinview:self]; [uiview animatewithduration:0.01f animations:^{ cgrect oldframe = _viewtochange.frame; _viewtochange.frame = cgrectmake(oldframe.origin.x, currentpoint.y, oldframe.size.width, ([uiscreen mainscreen].bounds.size.height - currentpoint.y)); }]; } doing does sort of work, uitableview flashes pull , disappears.
there no spring, , no way set "max" can't pull view past point.
does have ideas on how can achieved?
this how write pan:. t tableview(initially user interaction disabled). 40 in code more realistic in pan. 200 max value used , 60 min value. directly add t tableview height 60 , increased height animation.
- (void)pan:(uipangesturerecognizer *)apan; { cgpoint currentpoint = [apan locationinview:self.view]; cgrect fr = t.frame; if ((currentpoint.y - fr.origin.y) < 40 && (fr.size.height <= 200) ) { float nh = (currentpoint.y >= self.view.frame.size.height - 200) ? self.view.frame.size.height-currentpoint.y : 200; if (nh < 60) { nh = 60; } [uiview animatewithduration:0.01f animations:^{ [t setframe:cgrectmake(0, self.view.frame.size.height-nh, t.frame.size.width, nh)]; }]; if (nh == 200) { [t setuserinteractionenabled:yes]; } else { [t setuserinteractionenabled:no]; } } } or without pan; using tableview's scrollview delegate methods, when tableview begin dragging in closed state, opening large mode , when tableview scroll top sliding down
-(void)scrollviewwillbegindragging:(uiscrollview *)scrollview { nslog(@"scroll"); if (scrollview.contentoffset.y == 0) { [uiview animatewithduration:0.2f animations:^{ [scrollview setframe:cgrectmake(0, self.view.frame.size.height-200, t.frame.size.width, 200)]; }]; } } -(void)scrollviewdidscroll:(uiscrollview *)scrollview { if (scrollview.contentoffset.y == 0) { [uiview animatewithduration:0.2f animations:^{ [scrollview setframe:cgrectmake(0, self.view.frame.size.height-60, t.frame.size.width, 60)]; }]; } }
Comments
Post a Comment