【发布时间】:2016-08-17 06:32:21
【问题描述】:
这里我有三个视图,一个是左、中、右,所以我想添加滑动功能,我尝试了以下方式但仍然无法实现。我该怎么做。
代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UISwipeGestureRecognizer *gestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerRight:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.view addGestureRecognizer:gestureRecognizer];
//Left Swipe
UISwipeGestureRecognizer *gestureRecognizer2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandlerLeft:)];
[gestureRecognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:gestureRecognizer2];
}
右转
-(void)swipeHandlerRight:(id)sender
{
RightViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"RightViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0;
transition.type = kCATransitionFromRight;
// transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
[self presentViewController:videoScreen animated:NO completion:nil];
}
左转
-(void)swipeHandlerLeft:(id)sender
{
LeftViewController *videoScreen=[self.storyboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0;
transition.type = kCATransitionFromLeft;
// transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:kCATransition];
}
【问题讨论】:
-
您想要实现的目标,我认为您应该使用页面视图控制器或在启用分页的滚动视图中放置 3 个视图。根据您的要求使滚动视图宽度尽可能大。
-
这些方法一次都没有调用吗?
-
@NileshJha 当我添加断点并运行程序时,视图将被调用,当我向左滑动时,断点转到 leftViewController 和右侧相同,但中间标签仍然显示在那里,当我在各个屏幕上添加标签时向左滑动时,它应该显示左侧标签
-
你的控制器有
UINavigationController作为根视图控制器吗? -
Virat 检查我的答案
标签: ios objective-c uiswipegesturerecognizer