Simulate System camera image Cropping

Source: Internet
Author: User

Simulate System camera image Cropping

The effect is as follows:

Source code:

//// Rootviewcontroller. M // scrollview // copyright (c) 2014 y. x. all rights reserved. // # import "rootviewcontroller. H "@ interface rootviewcontroller () <uiscrollviewdelegate> {bool tapped;} @ property (nonatomic, strong) uiscrollview * scrollview; @ property (nonatomic, strong) uiimageview * imageview; @ property (strong, nonatomic) uitapgesturerecognizer * tapgesture; @ end @ implementation rootviewcontroller- (Void) viewdidload {[Super viewdidload]; self. view. backgroundcolor = [uicolor blackcolor]; // scrollview {_ scrollview = [[uiscrollview alloc] initwithframe: cgrectmake (0, 0,200,200)]; [self. view addsubview: _ scrollview]; _ scrollview. center = self. view. center; _ scrollview. delegate = self; _ scrollview. layer. borderwidth = 2.f; _ scrollview. layer. bordercolor = [uicolor redcolor]. cgcolor; _ scrollview. l Ayer. maskstobounds = no; // the scroll bar _ scrollview is not displayed. showshorizontalscrollindicator = no; _ scrollview. showsverticalscrollindicator = no; _ scrollview. bounceszoom = yes; _ scrollview. minimumzoomscale = 1.f; _ scrollview. maximumzoomscale = 10.f; _ scrollview. contentmode = uiviewcontentmodescaleaspectfit;} // picture _ imageview = [[uiimageview alloc] initwithframe: cgrectmake (0, 0,200,200)]; _ imageview. image = [Uiimage imagenamed: @ "back"]; _ imageview. contentmode = uiviewcontentmodescaleaspectfit; [_ scrollview addsubview: _ imageview]; // gesture _ tapgesture = [[financialloc] initwithtarget: Self action: @ selector (taprecognized :)]; [_ scrollview addgesturerecognizer: _ tapgesture];}-(void) taprecognized :( ID) sender {If (! Tapped) {cgpoint tappoint = [self. tapgesture locationoftouch: 0 inview: Self. tapgesture. view]; cgrect zoomrect = [self zoomrectforscrollview: Self. scrollview withscale: 6.0f withcenter: tappoint]; [self. scrollview zoomtorect: zoomrect animated: Yes]; tapped = yes;} else {[self. scrollview setzoomscale: 1.0f animated: Yes]; tapped = no; }}- (cgrect) Duplicate :( uiscrollview *) scrollview withscale :( float) scale withcenter :( cgpoint) center {cgrect zoomrect; zoomrect. size. height = scrollview. frame. size. height/scale; zoomrect. size. width = scrollview. frame. size. width/scale; zoomrect. origin. X = center. x-(zoomrect. size. width/2.0); zoomrect. origin. y = center. y-(zoomrect. size. height/2.0); Return zoomrect;} # pragma mark-uiscrollview proxy method-(uiview *) viewforzoominginscrollview :( uiscrollview *) scrollview {return self. imageview;} @ end

Note the following:

You need to pass the Image view in the uiscrollview proxy method.

How can this be used? If you need to capture an image in a certain area, you will know what it is :)

 

 

 

 

 

 

 

 

 

 

 

Simulate System camera image Cropping

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.