Iphone UIView.setalpha不工作?

Iphone UIView.setalpha不工作?,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我已经创建了一个显示在键盘上的栏,用于下一个/上一个/完成,就像safari浏览器一样。但是,该条UIview的setalpha属性似乎不起作用。无论我将其设置为什么值,都不会改变。这是代码 此处是创建视图的调用位置 -(void)textFieldDidBeginEditing:(UITextField *)textField{ // Call the createInputAccessoryView method we created earlier. // By doing that we

我已经创建了一个显示在键盘上的栏,用于下一个/上一个/完成,就像safari浏览器一样。但是,该条UIview的setalpha属性似乎不起作用。无论我将其设置为什么值,都不会改变。这是代码

此处是创建视图的调用位置

-(void)textFieldDidBeginEditing:(UITextField *)textField{
// Call the createInputAccessoryView method we created earlier.
// By doing that we will prepare the inputAccView.
[self createInputAccessoryView];
// Now add the view as an input accessory view to the selected textfield.
[textField setInputAccessoryView:inputAccView];
// Set the active field. We' ll need that if we want to move properly
// between our textfields.
txtActiveField = textField;
}
这里是我实际创建和设置其值的地方

-(void)createInputAccessoryView{
// Create the view that will play the part of the input accessory view.
// Note that the frame width (third value in the CGRectMake method)
// should change accordingly in landscape orientation. But we don’t care
// about that now.
inputAccView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 40.0)];
// Set the view’s background color. We’ ll set it here to gray. Use any color you want.
[inputAccView setBackgroundColor:[UIColor darkGrayColor]];
// We can play a little with transparency as well using the Alpha property. Normally
// you can leave it unchanged.
[inputAccView setAlpha: 0.1f];


... code for adding buttons and their properties

}
所以基本上这就是它的全部。但是setAlpha属性什么都不做,不管我将其设置为什么。不过,背景色效果很好。有什么想法吗


谢谢

出于好奇,请尝试使用:

UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 310.0, 40.0)];
overlay.backgroundColor = [UIColor blackColor];
overlay.alpha = 0.5f;
[self.view addSubview:overlay];

如果看不到您有多少视图以及如何堆叠视图,很难判断问题是什么。检查是否定义了“addSubview”以及层次结构的外观。如果希望它看起来像Safari中的上一个/下一个/完成栏等,请创建一个UIToolbar,样式设置为半透明黑色。这还有一个优点,就是你的按钮布置得很好,样式正确,并且可以在横向和纵向之间自动调整


这不是对你问题的直接回答,但可能是实现你真正想要的更好的方式。

奇怪。InputAcView.alpha=0.1f也不起作用吗?我看不到您将
InputAcView
添加为
子视图
也在想同样的事情。@basvk在第一个函数中//现在将视图作为输入附件视图添加到所选文本字段中。[textField setInputAccessoryView:InputAcView]@glogic当前的setAlpha行,0.1f没有改变任何东西。我考虑过这一点,但找不到一个好方法来“隐藏”大多数示例描述的工具栏是必要的。我的屏幕是在运行时构建的,它的大小未知。试图隐藏它在屏幕上的某个地方可能会导致它在屏幕的中间,取决于它是如何建立的。隐藏它是在键盘消失时由系统完成的。如果你愿意的话,我可以提供一些示例代码,不过(目前仅限于电话)我正在将视图添加到文本字段的InputAccessoryView中。我找到了一个工具栏解决方案,似乎可以适应我的动态UI。所以我要走那条路。虽然这个问题还没有解决,但已经没有必要了。谢谢大家的帮助!