如题,想点击屏幕,屏幕会有点暗半透明,手指离开屏幕,屏幕又恢复正常,和UIButton差不多。
在这种情况下,我知道UIButton
要容易得多,但这只是一个示例
我的代码如下:
- (IBAction)tapped:(UITapGestureRecognizer *)sender
{
UIView * tintView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.view addSubview:tintView];
switch (sender.state) {
case UIGestureRecognizerStateRecognized: {
[tintView setBackgroundColor:[UIColor colorWithRed:.25 green:.25 blue:.25 alpha:.5]];
NSLog(@"begin");
}
default: {
[tintView setBackgroundColor:[UIColor clearColor]];
NSLog(@"ended");
}
}
}
但是,当点击屏幕时,它不会像上面的代码那样改变,尽管begin
并且ended
被捕获在控制台中。
case
如果在和default
喜欢之间交换这些代码
switch (sender.state) {
case UIGestureRecognizerStateRecognized: {
[tintView setBackgroundColor:[UIColor clearColor]];
NSLog(@"begin");
}
default: {
[tintView setBackgroundColor:[UIColor colorWithRed:.25 green:.25 blue:.25 alpha:.5]];
NSLog(@"ended");
}
}
begin
并且ended
可以在控制台中显示,但是点击时屏幕会越来越暗,永远不会恢复正常,清晰的颜色。
我的代码有什么问题?如何让它发生?
谢谢!