【问题标题】:View home screen in iOS application (Swift)在 iOS 应用程序中查看主屏幕 (Swift)
【发布时间】:2019-04-28 13:17:00
【问题描述】:

如何使 UIView 的背景半透明,以便用户可以看到他们的(模糊的)主屏幕?

如果这不可行,也许我可以截屏主屏幕并添加半透明效果。在这种情况下,如何截取用户主屏幕的屏幕截图?

Apple 有严格的隐私观点(我支持),所以我知道以上任何一项都是不允许的。

【问题讨论】:

  • 我会回答你的第一个问题并说它在iOS 7之后不起作用

标签: ios swift uiview homescreen translucency


【解决方案1】:

1。为了获得前一个 UIViewController 的背景,将下一个控制器的presentationStyle 设置为overFullScreen。

let vc = ViewController()
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: true, completion: nil)

如果需要半透明效果使用,

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)

2。截屏。

func takeScreenshot(view: UIView) -> UIImageView {
     UIGraphicsBeginImageContext(view.frame.size)
     view.layer.render(in: UIGraphicsGetCurrentContext()!)
     let image = UIGraphicsGetImageFromCurrentImageContext()
     UIGraphicsEndImageContext()
     UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
     return UIImageView(image: image)   
}

let view = HomeScreen().view
let image = taketakeScreenshot(view)

【讨论】:

  • 感谢您的精彩回答!但是,Xcode 告诉我Use of unresolved identifier 'HomeScreen'。如何使用HomeScreen() 是否有特定条件,还是完全弃用?
  • @Benj,HomeScreen 是我想要的截图类。您可以将其替换为任何类或直接 UIView。抱歉回复晚了。
  • 哦,好的,对不起!我以为HomeScreen 是官方 API。
猜你喜欢
  • 2014-12-18
  • 1970-01-01
  • 2017-12-18
  • 1970-01-01
  • 1970-01-01
  • 2018-08-07
  • 2015-12-11
  • 1970-01-01
相关资源
最近更新 更多