1

我想在 iOS 中上下滑动UIViewController类似控制中心的主视图。

我看到 VC2 在 VC1 上可见一半。现在,当用户使用手指滑动 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)];
}];

}

有谁知道该怎么做?

4

0 回答 0