Master-Detail 视图的实现, 左右滑动显示隐藏Master视图

来源:互联网 发布:智者软件官网 编辑:程序博客网 时间:2024/06/07 22:40
- (void)loadView{UIView *v = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];self.view = v;v.backgroundColor = [UIColor blackColor];CGRect frame1 = CGRectMake(-masterWidth, 0, masterWidth, self.view.bounds.size.height);CGRect frame2 = self.view.bounds;mvc.view.frame = frame1;dvc.view.frame = frame2;[v addSubview:mvc.view];[v addSubview:dvc.view];UIPanGestureRecognizer *p = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];[self.view addGestureRecognizer:p];}- (void)pan:(UIPanGestureRecognizer *)p{UIView *v = p.view;if (p.state == UIGestureRecognizerStateBegan ||p.state == UIGestureRecognizerStateChanged) {CGPoint delta = [p translationInView:v.superview];if (delta.y != 0) {masterIsTendtoShow = (delta.y > 0) ? YES : NO;}[self moveMasterAndDetailViewOffsetToRight:delta.y];[p setTranslation:CGPointZero inView:v.superview];}else if (p.state == UIGestureRecognizerStateEnded) {[self showMaster:masterIsTendtoShow withAnimated:YES];}}

0 0