[Code Note] image gesture, upload photo, and gesture upload photo

Source: Internet
Author: User

[Code Note] image gesture, upload photo, and gesture upload photo

Code:

RootViewController. h

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>{    UIImageView *imageView;}@end

 

RootViewController. m

# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. self. ti Tle = @ "image gesture, upload photo"; // initialize the background image [self initBackgroundView];} # pragma-mark-functions-(void) initBackgroundView {imageView = [[UIImageView alloc] initWithFrame: CGRectMake (100,150,200,150)]; imageView. backgroundColor = [UIColor redColor]; [self. view addSubview: imageView]; [imageView setUserInteractionEnabled: YES]; UITapGestureRecognizer * clickGesture = [[UITapGestureRecognizer alloc] initWithTarget: self Action: @ selector (clickGesture :)]; [imageView addGestureRecognizer: clickGesture] ;}# pragma-mark-doClickActions-(void) clickGesture :( UIGestureRecognizer *) gesture {UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: @ "select image source" delegate: self cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "" otherButtonTitles: @ "Local album", nil]; [actionSheet showInView: self. view] ;}# pragma-mark UIActionSheetD Elegate-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex {NSLog (@ "-- buttonIndex-% ld", buttonIndex ); UIImagePickerController * pickView = [[UIImagePickerController alloc] init]; pickView. delegate = self; if (buttonIndex = 0 &&! TARGET_IPHONE_SIMULATOR) {// camera pickView. sourceType = UIImagePickerControllerSourceTypeCamera; [self presentViewController: pickView animated: NO completion: nil];} else if (buttonIndex = 1) {// album pickView. sourceType = signature; [self presentViewController: pickView animated: NO completion: nil] ;}# pragma-mark-signature-(void) imagePickerController :( UIImagePickerController *) picker syntax :( NSDictionary *) info {UIImage * image = [info objectForKey: Secret]; [imageView setImage: image]; [picker dismissViewControllerAnimated: NO completion: nil];}-(void) Complete :( UIImagePickerController *) picker {[picker dismissViewControllerAnimated: NO completion: nil];}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .}

 

 

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.