OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 PhotoLibrary 私有(private)框架设置 iOS 壁纸时,裁剪/缩放不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 23:47
标题: ios - 使用 PhotoLibrary 私有(private)框架设置 iOS 壁纸时,裁剪/缩放不起作用

我已经设法(在 post 的帮助下)从 PhotoLibrary 私有(private)框架中打开了一个 PLStaticWallpaperImageViewController,它允许直接设置壁纸和锁定屏幕(使用与照片应用程序)。不幸的是,图像裁剪/缩放功能似乎不起作用,因为对 ImageView 本身的触摸似乎没有通过(触摸取消/设置按钮后主视图也没有正确关闭,但这没那么重要)。

我有一个 Xcode 项目演示壁纸设置(可以在模拟器和非越狱设备中运行):

https://github.com/newenglander/WallpaperTest/

代码非常基础,包含一个继承自PLStaticWallpaperImageViewControllerViewController,并实现了一个类似如下的init方法:

- (id)initWithCoderNSCoder *)aDecoder {
    self = [self initWithUIImage:[UIImage imageWithContentsOfFile"/System/Library/WidgetResources /ibutton/[email protected]"]];
    self.allowsEditing = YES;
    self.saveWallpaperData = YES;
    return self;
}

(首次启动后需要允许访问照片库,并且出于某种原因,此弹出窗口出现在应用程序后面,而不是顶部。)

也许有人知道为什么裁剪/缩放不起作用,或者可以给我另一种在应用中设置壁纸的方法(当然是针对 Cydia 而不是 App Store)?



Best Answer-推荐答案


使用这个示例项目,效果很好。

具有内部相机控制和自定义布局,在拍摄或从您的库中选择后裁剪图像,我用于我的项目并且非常易于自定义。

https://github.com/yuvirajsinh/YCameraView

//---------- 答案改进----------//

我查看了您的项目,发现了 2 个问题:

这里有 3 个语义问题警告:

- (id)initWithUIImageid)arg1 cropRectstruct CGRect { struct CGPoint { float x_1_1_1; float x_1_1_2; } x1; struct CGSize { float x_2_1_1; float x_2_1_2; } x2; })arg2;

enter image description here

在你的 ViewController.m 你设置从哪里获取图像?

        - (id)initWithCoderNSCoder *)aDecoder
    {
        // black_i

//what directory is this?
        self = [self initWithUIImage:[UIImage imageWithContentsOfFile"/System/Library/WidgetResources/ibutton/[email protected]"]];
//--------------------
        self.allowsEditing = YES;
        self.saveWallpaperData = YES;

        return self;
    }

我尝试删除你的

- (id)initWithUIImageid)arg1 cropRectstruct CGRect { struct CGPoint { float x_1_1_1; float x_1_1_2; } x1; struct CGSize { float x_2_1_1; float x_2_1_2; } x2; })arg2;

将 IMG 目录更改为:

self = [self initWithUIImage:[UIImage imageNamed"myImage.png"]];

一切正常但无法裁剪图像,使用我的 git hub YCameraView 你首先了解它是如何工作的 CROPPING 功能如果你想使用裁剪或更简单,你必须创建一个全屏 UICameraPicker 允许用户从相机或库中获取并允许在 cameraPicker 中进行编辑,然后您可以像这样在 View 中加载新图片

self = [self initWithUIImage:[UIImage imageNamed:imageSelected.image]];

对于关闭 View ,您不能,因为是一个完整的应用程序允许用户设置背景壁纸,并且您不能终止应用程序以查看 SpringBoard,您必须创建第一个 View > 选择器 > 详细 View ,其中设置为一个 Home 和 LockScreen > 然后关闭并返回第一个 View 。

PS:我认为在您的项目中,要在 View 中直接编辑,您必须通过 UIView 上的捏合和平移手势来改进代码

希望对您有所帮助!

关于ios - 使用 PhotoLibrary 私有(private)框架设置 iOS 壁纸时,裁剪/缩放不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24696884/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4