小编Rag*_*ram的帖子

Swift - 如何检测方向变化

我想将两个图像添加到单个图像视图(即用于横向一个图像和用于纵向另一个图像),但我不知道如何使用快速语言检测方向变化.

我试过这个答案,但它只需要一张图片

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        print("Landscape")
    } else {
        print("Portrait")
    }
}
Run Code Online (Sandbox Code Playgroud)

我是iOS开发的新手,任何建议都将不胜感激!

ios swift

72
推荐指数
11
解决办法
8万
查看次数

swift:如何截取 AVPlayerLayer() 的截图

如何截取 AVplayerLayer 的截图。我尝试使用以下代码效果很好,它可以按原样捕获整个视图

func screenShotMethod() {
    let window = UIApplication.shared.delegate!.window!!
    //capture the entire window into an image
    UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.main.scale)
    window.drawHierarchy(in: window.bounds, afterScreenUpdates: false)
    let windowImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    //now position the image x/y away from the top-left corner to get the portion we want
    UIGraphicsBeginImageContext(view.frame.size)
    windowImage?.draw(at: CGPoint(x: -view.frame.origin.x, y: -view.frame.origin.y))
    let croppedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext();
    //embed image in an imageView, supports transforms.
    let resultImageView = UIImageView(image: croppedImage)
    UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil)
}
Run Code Online (Sandbox Code Playgroud)

但问题是当我尝试在 iPhone(设备)上运行相同的代码时,它返回黑色图像。我不知道出了什么问题

任何建议都会非常有帮助!

screenshot ios avplayer swift

5
推荐指数
1
解决办法
2908
查看次数

标签 统计

ios ×2

swift ×2

avplayer ×1

screenshot ×1