在iOS应用程序中查看主屏幕(快速)

时间:2019-04-28 13:17:00

标签: ios swift uiview homescreen translucency

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

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

Apple拥有严格的隐私保护观点(我支持),因此我了解以上内容均不允许。

1 个答案:

答案 0 :(得分:1)

1。为了具有上一个UIViewController的背景,请将下一个控制器的PresentationStyle呈现为overFullScreen。

import urllib.request

import bs4 as bs

source = urllib.request.urlopen('https://store.steampowered.com/search/?filter=weeklongdeals')
soup = bs.BeautifulSoup(source,'lxml')

searchResultContainer = soup.find('div',{'id':'search_result_container'})
containerHolder = searchResultContainer.findChildren()[1]

links = []
for a in containerHolder.findAll('a', href=True):
    links.append(a['href'])

x = 0
description = []
for link in links:
    source = urllib.request.urlopen(str(link))
    soup = bs.BeautifulSoup(source,'lxml')

    try: 
        test = soup.find('div',{'class':'game_description_snippet'}).get_text().strip()
        description.append(soup.find('div',{'class':'game_description_snippet'}).get_text().strip())
    except:
        test = 'No description'
        description.append('No description')
    finally:
        x += 1
        print(f'{x}: {test}')

如果需要半透明效果,

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

2。要截图。

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)
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)   
}