我尝试使用UIView
子视图制作UIVisualEffectView
作为效果UIBlurEffect
。视图在屏幕一侧创建,然后使用动画滑入。
在模拟器上一切正常(我已在iPhone 4S和iPhone 6上测试过)但是在我的手机(iPhone 6)上,模糊不会模糊,看起来更像是黑暗灰色,alpha
为0.5。此外,当我拍摄设备的屏幕截图或从主屏幕打开它时,在一致渲染再次开始之前,将为该单帧渲染模糊。
此处是目前视图的屏幕截图:
然而,在设备上,模糊不存在,它基本上只是一个黑暗透明的视图。
这是我用来初始化视图的代码,blurView
和vibrancyView
属性被声明为全局变量:
init(left: Bool){
self.left = left
let screenSize = UIScreen.mainScreen().bounds.size
var rect: CGRect
if left{
rect = CGRectMake(-screenSize.width*0.3, 0, screenSize.width*0.3, screenSize.height)
}else{
rect = CGRectMake(screenSize.width, 0, screenSize.width*0.3, screenSize.height)
}
super.init(frame: rect)
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = CGRectMake(0, 0, self.frame.width, self.frame.height)
self.addSubview(blurView)
let vibrancy = UIVibrancyEffect(forBlurEffect: blurEffect)
vibrancyView = UIVisualEffectView(effect: vibrancy)
vibrancyView.frame = blurView.frame
blurView.addSubview(vibrancyView)
self.userInteractionEnabled = true
}
并移动包含blurView的superView:
func moveIn(){
UIView.animateWithDuration(0.3, animations: { () -> Void in
var center = self.center
if self.left{
center.x = UIScreen.mainScreen().bounds.size.width*0.15
}else{
center.x = UIScreen.mainScreen().bounds.size.width*0.85
}
self.center = center
})
}
正如我在动画之前说的那样,这样的工作很好但是blurView并不模糊。
我不确定这是怎么回事,它让我觉得它与渲染帧有关但我不是大师,所以如果有人有任何想法我和#39;不仅仅是感激。
答案 0 :(得分:3)
要关闭它,这是因为我在大多数应用程序中使用SpriteKit,因此使用SKView而不是UIView。我意识到我没有在问题中提到这一点,但我不知道这将是一个问题。显然,SKView遵循不同的渲染路径,因此不会模糊,建议的方法是效果节点。
答案 1 :(得分:0)
blurView.frame = CGRectMake(0, 0, self.frame.width, self.frame.height)
中的行self.frame
中的在layoutSubviews之前可以为零。 当self.frame存在时设置blurView框架