我正在尝试将 UIView 作为附件视图添加到 UITextField,但似乎不尊重 alpha 属性。
这是我当前的代码。
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;
alpha 值似乎无关紧要。无论我将其设置为什么,accessoryView 始终设置为不透明。
我想要完成的是在键盘上方显示一个透明视图,只要用户从键盘上轻按,它就会关闭键盘。如果有更好/正确的方法来做到这一点,我完全错过了,我也会全神贯注。
- 编辑 *
我知道我可以只[UIColor clearColor]
用作背景颜色,但我更想知道为什么不支持 alpha 设置,以防我真的想要一个半透明的附件视图