我有兴趣尝试修改允许从一个视图到另一个视图的全屏滑动的功能,以便创建一个"滑块"这是整个页面的大小 - 即在页面上的任何位置拖动/滑动/滑动都会产生某种影响。
它不需要是可见的。例如,我可能有一个坚实的红色屏幕,我可以通过向右拖动到任何地方来改变颜色,让它逐渐变为蓝色。
这可能吗?
答案 0 :(得分:0)
使用UIPanGestureRecognizer,您可以在屏幕上跟踪手指移动,然后使用translationInView查找用户手指移动了多少,并根据该数字以某种方式更改颜色
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
处理它:
-(void)handlePan:(UIPanGestureRecognizer*)sender
{
CGFloat xMovement = [sender translationInView:sender.view].x;
// Do something with the movement
// Then reset the translation
[sender setTranslation:CGPointZero inView:sender.view];
}