我想制作一个表单,以模态方式呈现,部分透明,类似于音量表或控制中心在 iOS 7+ 中的部分透明方式。
我正在使用 XCode 6.3.2、Swift 1.2 进行编程,它适用于 iOS 8 平台 (iPad)。
我尝试了以下方法:
Setting the ViewController's alpha value in Storyboard to 0.5
背景颜色结果显得更暗,但不透明,文字显得微弱。
Setting background color in Storyboard to "Clear Color"
背景颜色看起来更暗,没有注意到更暗的文字。
Setting background color to a color with 30% transparency
同上。
De - selecting
Clears Graphics Content
最终结果没有明显变化。
澄清一下,我想要在 iPad 上使用部分透明的模态视图,而不是较暗的背景。
有什么方法可以在 Swift 或 Storyboard 中做到这一点?
最佳答案
Rocket101,这是我用来实现类似效果的代码。它在 Objective C 中,但您应该能够轻松翻译它。 在登录期间,我用“coverView”阻止了我当前的 View ,它显示了一个模糊的 Logo 。在您的情况下,您不会包含“backgroundImage”。 这是我创建模糊效果的方法。
UIView *coverView = [[UIView alloc] init];
coverView.frame = self.tabBarController.view.bounds;
UIImage *backgroundImage = [UIImage imageNamed:@"SomeBackgroundImage"];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
backgroundView.frame = self.tabBarController.view.bounds;
UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
effectView.frame = self.tabBarController.view.bounds;
effectView.alpha = 0.8;
[coverView addSubview:backgroundView];
[coverView addSubview:effectView];
[coverView sendSubviewToBack:effectView];
[coverView sendSubviewToBack:backgroundView];
[theView addSubview:coverView];
关于ios - iPad 上的模态表单在 Swift 中透明吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32208830/