Copy/cut/paste pictures in the screen

Source: Internet
Author: User

Using touchesended:withevent: Customizing the Copy-and-paste menu, copy: Copying the picture on the screen, cut: Cutting the picture on the screen, paste: pasting the picture from the screen.

1 @implementationPrjcopyandpaste2 3-(void) Viewdidload4 {5 [Super Viewdidload];6 }7 8-(void) Viewwillappear: (BOOL) Animated9 {Ten [Super viewwillappear:animated]; OneSelf.view.backgroundColor =[Uicolor Whitecolor]; A      -[Self Setupimagewithname:@"img_01"Center:self.view.center]; -[Self Setupimagewithname:@"img_02"Center:cgpointmake ( $, -)]; the[Self Setupimagewithname:@"img_03"Center:cgpointmake ( -, the)]; - } -  --(void) Setupimagewithname: (NSString *) imagenamed Center: (cgpoint) Point + { -Uiimageview *bug =[[Uiimageview alloc]initwithimage:[uiimage imagenamed:imagenamed]]; +Bug.center =Point ; A [Self.view Addsubview:bug]; at } - //become the first responder Show Edit menu --(BOOL) Canbecomefirstresponder - { -     returnYES; - } in  --(void) touchesended: (Nsset *) touches withevent: (Uievent *)Event to { +Uitouch *touch =[touches anyobject]; -     //two consecutive touch display menus the     if([Self becomefirstresponder] &&1<[Touch Tapcount]) { *Uimenucontroller *menu =[Uimenucontroller Sharedmenucontroller]; $Self.touchpoint =[Touch LocationInView:self.view];Panax Notoginseng CGRect Minrect; -Minrect.origin =Self.touchpoint; the [Menu Settargetrect:minrect InView:self.view]; + [Menu Setmenuvisible:yes animated:yes]; A     } the } +  --(BOOL) Canperformaction: (SEL) Action Withsender: (ID) Sender $ { $     if(@selector (copy:) = =action) { -         if([self imageContainsPoint:self.touchPoint]) { -             returnYES; the         } -}Else if(@selector (cut:) = =action) {Wuyi         if([self imageContainsPoint:self.touchPoint]) { the             returnYES; -         } Wu}Else if(@selector (paste:) = =action) { -         return(Nil! =[Uipasteboard generalpasteboard].image); About     } $     returnNO; - } -  --(Uiimageview *) Imagecontainspoint: (cgpoint) Point A { +      for(UIView *viewinchself.view.subviews) { the         if(Cgrectcontainspoint (View.frame, point)) { -             if([View Iskindofclass:[uiimageviewclass]]) { $                 return(Uiimageview *) view; the             } the         } the     } the     returnNil; - } in-(void) Copy: (ID) Sender the { theUiimageview *imageview =[self imageContainsPoint:self.touchPoint]; About     if(ImageView) { the[Uipasteboard generalpasteboard].image =Imageview.image; the     } the } +-(void) Cut: (ID) Sender - { theUiimageview *imageview =[self imageContainsPoint:self.touchPoint];Bayi     if(ImageView) { the [ImageView Removefromsuperview]; the     } - } --(void) Paste: (ID) Sender the { theUipasteboard *pasteboard =[Uipasteboard Generalpasteboard]; the     if(pasteboard.image) { theUiimageview *bug =[[Uiimageview alloc] initWithImage:pasteboard.image]; -Bug.center =Self.touchpoint; the [Self.view Addsubview:bug]; thePasteboard.image =Bug.image; the     }94 } the  the  the @end
View Code

Achieve results

Copy/cut/paste pictures in the screen

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.