[英]Set alpha transparency on accessoryView
I am trying to add a UIView as an accessoryView to a UITextField, but the alpha property doesnt seem to be respected. 我试图将UIView作为附件视图添加到UITextField,但是似乎不尊重alpha属性。
Here is my current code. 这是我当前的代码。
self.keyboardAccView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
[self.keyboardAccView setBackgroundColor:[UIColor lightGrayColor]];
[self.keyboardAccView setOpaque:NO];
[self.keyboardAccView setAlpha:0.0];
UITapGestureRecognizer *hideKeyboardTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];
[self.keyboardAccView addGestureRecognizer:hideKeyboardTap];
[hideKeyboardTap release], hideKeyboardTap=nil;
The alpha value doesnt seem to matter. alpha值似乎无关紧要。 No matter what I set it to, the accessoryView is always set to no transparency.
无论我将其设置为什么,accessoryView始终设置为不透明。
What I'm trying to accomplish is show a transparent view above the keyboard that will dismiss the keyboard anytime the user taps away from the keyboard. 我要完成的工作是在键盘上方显示一个透明视图,只要用户从键盘上轻按一下,它便会关闭键盘。 If there is a better/proper way to do this that I am completely missing, I'm all ears as well.
如果有一种更好/合适的方法来使我完全不知所措,那么我也会全神贯注。
I know I could just use [UIColor clearColor]
as the backgroundColor but I more want to know why the alpha setting isnt honored, in case I truly did want to have a semi-transparent accessoryView 我知道我可以只使用
[UIColor clearColor]
作为backgroundColor,但我更想知道为什么不采用alpha设置,以防万一我确实确实想要一个半透明的AccessoriesView
yes - there is a better way to do it! 是的-有更好的方法! :)
:)
I personally do it like this - I change my ViewController.xib class (UIView to UIControl) and then I create a simple IBAction which resigns first responder whenever is the UIControl tapped. 我个人是这样做的-我更改了ViewController.xib类(将UIView更改为UIControl),然后创建了一个简单的IBAction,只要轻按了UIControl,它就会辞职第一响应者。
The method should look like this: 该方法应如下所示:
- (IBAction)hideKeyboard {
[textField resignFirstResponder];
}
That's it :) 而已 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.