像iOS 8中的控制中心一样向上和向下滑动

时间:2016-06-27 13:21:16

标签: ios uipangesturerecognizer swipe-gesture ios-animations

我想在iOS {中像控件中心一样向上和向下滑动UIViewController的主视图。

我看到VC1上可见一半的VC2。现在,当用户使用手指滑动VC2的视图时,它将像控制中心一样上下滑动。

我使用UISwipeGestureRecognizer向上和向下滑动,但它不像iOS中的控制中心那样动画

修改

- (void)viewDidLoad {
       [super viewDidLoad];

       UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDownHandler:)];
      [gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
      [self.view addGestureRecognizer:gestureRecognizer];

      UISwipeGestureRecognizer *gestureRecognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpHandler:)];
      [gestureRecognizer1 setDirection:(UISwipeGestureRecognizerDirectionUp)];
      [self.view addGestureRecognizer:gestureRecognizer1];
}

-(void)swipeUpHandler:(UISwipeGestureRecognizer *)recognizer{
      [UIView animateWithDuration:0.3 animations:^{
    [self.view setFrame:CGRectMake(0,25, self.view.frame.size.width, self.view.frame.size.height)];
}];
}

-(void)swipeDownHandler:(UISwipeGestureRecognizer *)recognizer {
      [UIView animateWithDuration:0.3 animations:^{
    [self.view setFrame:CGRectMake(0,self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
}];

}

任何人都知道该怎么办?

0 个答案:

没有答案