我的视图控制器中有一个图像视图。当向下滑动手势被识别时,我想要关闭视图控制器。虽然我已经实现了通过手势关闭视图控制器,但我正在尝试弄清楚如何在关闭前添加动画,就像iPhone中的照片应用程序一样。
-(void)addPanGesture{
UIPanGestureRecognizer *gestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(dismissViewGes:)];
gestureRecognizer.delegate = self;
[self.view addGestureRecognizer:gestureRecognizer];
}
-(void)dismissViewGes:(UIPanGestureRecognizer *)gesture {
CGPoint velocity = [gesture velocityInView:self.view];
if(velocity.y > 0)
{
CATransition *transition = [[CATransition alloc]init];
transition.duration = 2;
[transition setValue:[NSNumber numberWithFloat:0.5f] forKey:kCATransitionFade];
transition.subtype = kCATransitionFromTop;
[self.view.layer addAnimation:transition forKey:nil];
[[NetWrapper shared] addRemovedController:self];
[self dismissViewControllerAnimated:NO completion:nil];
}
}
我尝试添加CATransition,希望淡出动画能够起作用,但它并没有起作用,视图在应用滑动手势后立即关闭。
如何在视图关闭时添加淡出效果,就像照片应用程序中一样。
[UIView animateWithDuration:2.0f animations:^{ [self.view setAlpha:0.5]; } completion:^(BOOL finished) { [UIView animateWithDuration:0.3f animations:^{ [self.view setAlpha:0.1]; } completion:^(BOOL finished) { //[[NetWrapper shared] addRemovedController:self]; [self dismissViewControllerAnimated:NO completion:nil]; }]; }];
- SriTeja Chilakamarri