我正在尝试打开一个背景模糊的ModalView(但周围有一些空间)
为什么这段代码会忽略inset / frame命令?我可以看到模糊的图像。但它是全屏的。
PS:此VC通过Storyboard分配
class InfoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.setupView()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func setupView() {
// Add some space around the view
self.view.clipsToBounds = true
self.view.frame = UIEdgeInsetsInsetRect(self.view.frame, UIEdgeInsetsMake(20, 10, 10, 10)) // <-- not working?
// Take screenshot from parent VC
let parentVC : UIViewController = self.presentingViewController
UIGraphicsBeginImageContext(parentVC.view.bounds.size)
parentVC.view.drawViewHierarchyInRect(parentVC.view.bounds, afterScreenUpdates:true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
// Blur screnshot
image = image.applyBlurWithRadius(20, tintColor: UIColor(white: 1.0, alpha: 0.2), saturationDeltaFactor: 1.3, maskImage: nil)
// Add screenshot to view
let backgroundImageView : UIImageView = UIImageView(image:image)
self.view.addSubview(backgroundImageView)
}
}