我有一个应用程序,我试图让用户通过手势使显示变暗。我有一个 UIView,其中包含许多其他视图和按钮,并且在其上放置了一个 UIView,其背景颜色设置为黑色。为了不进行调光,我将该调光器视图的 alpha 设置为零(透明)。为了实现调光,我小步增加了 alpha 值。这似乎工作得很好,除了......(你知道那会发生)每当 alpha 值变得大于零时,触摸事件被阻止 - 没有正常接收。
创建调光器视图:
UIPanGestureRecognizer * panner = nil;
panner = [[UIPanGestureRecognizer alloc] initWithTarget: self action:@selector(handlePanGesture:)];
[self.view addGestureRecognizer:panner ];
[panner setDelegate:self];
[panner release];
CGRect frame = CGRectMake(0, 0, 320, 460);
self.dimmer = [[UIView alloc] initWithFrame:frame];
[self.dimmer setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:dimmer];
处理平移手势:
-(IBAction) handlePanGesture:(UIPanGestureRecognizer *) sender
{
static CGPoint lastPosition = {0};
CGPoint nowPosition;
float alpha = 0.0;
float new_alpha = 0.0;
nowPosition = [sender translationInView: [self view]];
alpha = [dimmer alpha];
if (nowPosition.y > lastPosition.y)
{ NSLog(@"Down");
new_alpha = min(alpha + 0.02,1.0);
[dimmer setAlpha:(new_alpha)];
}
else if (nowPosition.y < lastPosition.y)
{
NSLog(@"Up");
new_alpha = max(alpha - 0.02,0);
[dimmer setAlpha:(new_alpha)];
}
else
{ NSLog(@" neither "); }
NSLog(@"alpha = %f new_alpha = %f", alpha, new_alpha);
lastPosition = nowPosition;
}
任何想法为什么事件被阻止?有一个更好的方法吗?
我已经阅读了几篇文章并在谷歌上搜索了很多,但没有看到任何非常相关的内容。
任何和所有的帮助表示赞赏。
:bp: