我基本上是在这里创建一个屏幕调光器。我在屏幕上放置了一个黑色视图,并使用 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: 选择器停止被调用。谁能描述导致此问题的原因?