Cropping/zooming not working while setting iOS Wallpaper using PhotoLibrary private framework

无人久伴 提交于 2019-12-10 11:09:24

问题


I have managed (with the help of this post) to open up a PLStaticWallpaperImageViewController from the PhotoLibrary private framework, which allows the direct setting of the wallpaper and lock screen (using same UI as the Photos app). Unfortunately, the image cropping/zooming features don't seem to work, as touches to the image view itself don't seem to be coming through (the main view is also not dismissed properly after the cancel/set buttons are touched, but this isn't so important).

I have an Xcode project demonstrating the wallpaper setting (can be run in simulator as well as a non-jailbroken device):

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

The code is quite basic, and involves a ViewController inheriting from PLStaticWallpaperImageViewController and implementing an init method similar to the following:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [self initWithUIImage:[UIImage imageWithContentsOfFile:@"/System/Library/WidgetResources /ibutton/white_i@2x.png"]];
    self.allowsEditing = YES;
    self.saveWallpaperData = YES;
    return self;
}

(It will be necessary to allow access to the photo library after the first launch, and for some reason the popup for this comes up behind the app, rather than on top.)

Perhaps someone has insight as to why the cropping/zooming isn't working, or can give me an alternative way to set the wallpaper in an app (destined for Cydia rather than the App Store of course)?


回答1:


Use this sample project, working very well.

Have inside camera control and custom layout, crop image when taken or after chose from your library, i used for my project and in very simple to customize.

https://github.com/yuvirajsinh/YCameraView

//---------- Answer improved----------//

I take a look on your project and i see 2 problem:

here you have 3 warning of semantic issue:

- (id)initWithUIImage:(id)arg1 cropRect:(struct 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;

in your ViewController.m you setting to get the image from where?

        - (id)initWithCoder:(NSCoder *)aDecoder
    {
        // black_i

//what directory is this?
        self = [self initWithUIImage:[UIImage imageWithContentsOfFile:@"/System/Library/WidgetResources/ibutton/white_i@2x.png"]];
//--------------------
        self.allowsEditing = YES;
        self.saveWallpaperData = YES;

        return self;
    }

i try to remove your

- (id)initWithUIImage:(id)arg1 cropRect:(struct 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;

change IMG directory in to:

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

and all working well but can't crop image, with my git hub YCameraView you have first understand how it work CROPPING function if you want to use crop or more simple, you have to create a fullScreen UICameraPicker allow user to get from camera or from library and allow the editing in cameraPicker then you can load a new picture in your View like this

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

for a dismiss view, you can't because is a full app allow user to setUp background wallpaper and you can't terminate the app to see a SpringBoard, you have to create first view > picker > detail view with settings for a Home and LockScreen > then dismiss and come back to a first view.

PS: I think in your project to enable editing direct in a view you have to improve your code with a pinch and pan gesture on the UIView

Hope this help you!



来源:https://stackoverflow.com/questions/24696884/cropping-zooming-not-working-while-setting-ios-wallpaper-using-photolibrary-priv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!