[IOS] Image Browsing effect (double-click the image and the pop-up layer)

Source: Internet
Author: User
# Import <uikit/uikit. h> # import <quartzcore/quartzcore. h> @ interface enlargeimagedoubletap: uiimageview {uiview * parentview; // The parent window, that is, the uiview uiimageview * imagebackground added by uiimageex; // The background uiview * imagebackview after the image is enlarged; // uiview * maskview for independent viewing; // mask layer cgrect framerect;} @ property (nonatomic, retain) uiview * parentview; @ property (nonatomic, retain) uiimageview * imagebackground; @ property (nonatomic, retain) uiview * imagebackview; @ property (nonatomic, retain) uiview * maskview;-(void) handledoubletap :( uitapgesturerecognizer *) recognizer; // required-(void) setdoubletap :( uiview *) imageview; @ end

# Import "enlargeimagedoubletap. H "@ implementation enlargeimagedoubletap @ synthesize parentview; @ synthesize imagebackground, imagebackview, maskview; @ interface timeout (private)-(void) fadein;-(void) fadeout;-(void) closeimage :( ID) sender; @ end/** setdoubletap initialize image * @ parent uiview parent window */-(void) setdoubletap :( uiview *) parent {parentview = parent; parentview. userinteractionenabled = yes; self. userinteractionenabled = yes; optional * doubletaprecognize = [[uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (handledoubletap :)]; doubletaprecognize. topology = 2; [doubletaprecognize setenabled: Yes]; [doubletaprecognize delaystouchesbegan]; [doubletaprecognize cancelstouchesinview]; [self topology: doubletaprecognize];} # pragma uigesturerecognizer handles/** handledoubletap double-click the image to bring up a separate picture layer * recognizer double-click gesture */-(void) handledoubletap :( uitapgesturerecognizer *) recognizer {if) {If ([[uidevice currentdevice] orientation] = bytes | [[uidevice currentdevice] orientation] = uideviceorientationlandscaperight) {framerect = cgrectmake (0, 0, parentview. frame. size. height + 20, parentview. frame. size. width);} else {framerect = cgrectmake (0, 0, parentview. frame. size. width, parentview. frame. size. height + 20);} imagebackview = [[uiview alloc] initwithframe: cgrectmake (0, 0, self. image. size. width + 20, self. image. size. height + 60)]; imagebackview. backgroundcolor = [uicolor graycolor]; imagebackview. layer. cornerradius = 10.0; // adjust [[imagebackview layer] setshadowoffset: cgsizemake (10, 10)] as needed; [[imagebackview layer] setshadowradius: 5]; [[imagebackview layer] setshadowopacity: 0.7]; [[imagebackview layer] setshadowcolor: [uicolor blackcolor]. cgcolor]; maskview = [[uiview alloc] initwithframe: framerect]; maskview. backgroundcolor = [uicolor graycolor]; maskview. alpha = 0.7; uiimage * imagepic = self. image; uiimageview * view = [[uiimageview alloc] initwithframe: cgrectmake (10, 30, self. image. size. width, self. image. size. height)]; [view setimage: imagepic]; uibutton * BTN = [uibutton buttonwithtype: Hangzhou]; uiimage * closeimg = [uiimage imagenamed: @ "closeimage.png"]; BTN. frame = cgrectmake (self. image. size. width-30, 0, closeimg. size. width, closeimg. size. height); [BTN setbackgroundimage: closeimg forstate: uicontrolstatenormal]; [BTN addtarget: Self action: @ selector (closeimage :) forcontrolevents: timer]; [imagebackview addsubview: View]; [parentview addsubview: maskview]; imagebackview. center = cgpointmake (framerect. origin. X + framerect. size. width)/2, (framerect. origin. Y + framerect. size. height)/2); [parentview addsubview: imagebackview]; [imagebackview addsubview: BTN]; [parentview bringsubviewtofront: imagebackview]; [self fadein];} /** fadein image fade into animation */-(void) fadein {imagebackview. transform = cgaffinetransformmakescale (1.3, 1.3); imagebackview. alpha = 0; [uiview animatewithduration :. 55 animations: ^ {imagebackview. alpha = 1; imagebackview. transform = cgaffinetransformmakescale (1, 1) ;}] ;}/ ** fadeout animation gradually disappears */-(void) fadeout {[uiview animatewithduration :. 35 animations: ^ {imagebackview. transform = cgaffinetransformmakescale (1.3, 1.3); imagebackview. alpha = 0.0;} completion: ^ (bool finished) {If (finished) {[imagebackview removefromsuperview] ;}}];} /** closeimage close the pop-up Image Layer */-(void) closeimage :( ID) sender {[self fadeout]; imagebackview = nil; [maskview removefromsuperview]; maskview = nil ;} @ end

After running:

Example download connection: http://download.csdn.net/detail/toss156/4160496

Related Article

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.