Presenting an image cropping interface

血红的双手。 提交于 2019-12-30 05:11:13

问题


I'm trying to engineer a UI for cropping images in iphone OS and suspect I'm going about things the hard way. My goal is pretty much what the Tapbots duo have done with Pastebot. In that app, they dim the source image but provide a movable and resizable cropping view and the image you're cropping is in a zoomable scrollview; when you resize or move the underlying image, the cropping view adjusts appropriately.

I mocked up a composite image which will give a sense of the design I'm after, along with how I presently have my view hierarchy setup. alt text http://grab.by/3TN4

The approach I've started with is the following: UIImageView with the image to crop is in a scrollview, a plain UIView with black fill and suitable transparency/alpha setting is added in front of the imageview. I then use a custom UIView which is a sibling to the scrollview at a higher level, which implements the drawRect: method and for the most part calls CGImageCreateWithImageInRect to get the portion of the image's bitmap that matches the position of the cropping view and draws that to the CGContext.

in the viewcontroller I'm using the UIScrollViewDelegate methods to track scrolling and passing those changes to the custom cropping UIView so it stays in sync with the scroll contentOffset. That much is finally working. But trying to keep in sync as the scrollview zoomScale changes is when I figured I should ask for help.

Looking for suggestions or guidance. My initial approach just seems like more work than is required.

Could this be done with a masking layer in the ImageView? And if so, how would I setup the tracking for moving and resizing the cropping rect? My experience working with layers is non-nil, but very limited thus far.


回答1:


For record's sake - A ready made component on Cocoa Controls

http://cocoacontrols.com/platforms/ios/controls/imagecropper




回答2:


I have found that often a better UI for cropping results if you think of manipulating the position and size (and even rotation) of an image underneath a simple, immovable mask or cropping rect rather than trying to move a mask or cropping rect on top of an unmoving image. This is especially true of you always want the cropped image to have a preset proportion and orientation.



来源:https://stackoverflow.com/questions/2679937/presenting-an-image-cropping-interface

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