我有一个 UIViewController 派生类,我想做的是有一个不透明的 subview ,而其父 View (主 UIViewController.view)具有 50% 的透明度。
在 Controller 类的 viewDidLoad 上,我设置了 View 和 subview 的 alpha 值。但是,我看到的是基本 View 和 subview 都是半透明的。有没有办法避免这种情况发生?
// Class declaration
@interface MyViewControllerClass : UIViewController
{ }
@property (nonatomic, strong) IBOutlet UIView *contentView;
@end
// Class implementation
- (void)viewDidLoad
{
// I want the main view to be a transparent overlay
[self.view setBackgroundColor:[UIColor lightGrayColor]];
[self.view setAlpha:0.5];
// This is the subview I want to look normal
[self.contentView setAlpha:1.0];
[self.contentView setOpaque:NO];
[super viewDidLoad];
}
最佳答案
你不能这么做。您需要以另一种方式安排您的 View 才能获得您想要的效果。尝试将另一个 UIView 添加到主视图并将其透明度设置为 50%。这样您的其他项目就可以保留在主视图上而不会受到影响。
关于iphone - 如何在 subview 正常的情况下获得半透明 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9388420/