1
我基本上是在这里创建一个屏幕调光器。我在屏幕上放置了黑色视图,并使用UIPanGestureRecognizer根据用户是向上还是向下滚动来调整不透明度。这里是代码:UIPanGestureRecognizer在平移时停止工作,而不是在平移时不工作
- (IBAction)dimScreen:(UIPanGestureRecognizer *)sender {
//Get translation
CGPoint translation = [sender translationInView:self.view];
CGFloat distance = translation.y;
//add a fraction of the translation to the alpha
CGFloat newAlpha = self.blackScreen.alpha + distance/self.view.frame.size.height;
//check if the alpha is more than 1 or less than 0
if (newAlpha>1) {
newAlpha = 1;
}else if (newAlpha<0.0){
newAlpha = 0.0;
}
self.blackScreen.alpha = newAlpha;
//reset translation to get incremental change
[sender setTranslation:CGPointZero inView:self.view];
}
如果我平移下来,不透明度达到1.0,我仍然可以调整它。如果我平铺直到不透明度为0,我就再也不能平移了。 dimScreen:选择器停止呼叫。任何人都可以描述是什么造成这个问题?
添加gesturerecognizer时显示代码。 – Arbitur
嗨Arbitur,在界面生成器中添加了gesturerecognizer。 –
尝试通过代码添加它,我有问题通过界面构建器添加gesturerecognizers。 – Arbitur