Machine questions: Map positioning, taking pictures, displaying, recording videos, playing, and recording questions

Source: Internet
Author: User

Machine questions: Map positioning, taking pictures, displaying, recording videos, playing, and recording questions

During the two-day interview, a company first obtained an exam and then went to the next step: map location, take a photo and display a photo, record a video, and play a video.

First, go to my:

  

 

1. Key code for map positioning (after ios8 is enabled, you must set the description in the project file ):

// 1. Add the map view CGRect rect = [UIScreen mainScreen]. bounds; _ mapView = [[MKMapView alloc] initWithFrame: CGRectMake (0, 50, rect. size. width, rect. size. height-50)]; [self. view addSubview: _ mapView]; // sets proxy _ mapView. delegate = self; // 2. Request to locate the service _ locationManager = [[CLLocationManager alloc] init]; if (! [CLLocationManager locationServicesEnabled] | [CLLocationManager authorizationStatus]! = Map) {[_ locationManager requestWhenInUseAuthorization];} // 3. User location track_mapview. userTrackingMode = MKUserTrackingModeFollow; // 4. Set map type _ mapView. mapType = MKMapTypeStandard;View Code

 

2. Key code for photographing and recording videos:

# Import "ViewController. h "# import <MobileCoreServices/MobileCoreServices. h> # import <MediaPlayer/MediaPlayer. h> @ interface ViewController () <strong, UIImagePickerControllerDelegate> @ property (weak, nonatomic) IBOutlet UIImageView * imgView; // display the photo @ property (strong, nonatomic) UIImagePickerController * picker; @ property (assign, nonatomic) BOOL isChange; // whether to switch between the camera and recorded video @ property (Assign, nonatomic) NSInteger currentTag; // current tag @ property (nonatomic, strong) MPMoviePlayerController * moviePlayer; // video playback controller @ property (nonatomic, strong) NSURL * movieUrl; // video recording path @ property (nonatomic, strong) UIView * movieView; // player View @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} // initialize picke R-(UIImagePickerController *) picker {if (_ isChange | _ picker = nil) {_ picker = [[UIImagePickerController alloc] init]; _ picker. sourceType = UIImagePickerControllerSourceTypeCamera; // set the source of image picker _ picker. cameraDevice = UIImagePickerControllerCameraDeviceRear; // you can specify the camera to use. Set this parameter to the rear camera if (self. currentTag = 1) {// record video _ picker. mediaTypes = @ [(NSString *) kUTTypeMovie]; _ picker. videoQuality = UIIm AgePickerControllerQualityTypeIFrame1280x720; _ picker. cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; // sets the Camera mode (photograph, recording video) // NSLog (@ "recording video");} else {// _ picker. cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; // remove the video player control if (self. moviePlayer! = Nil) {[self. movieView removeFromSuperview]; self. moviePlayer = nil; }}_ picker. allowsEditing = YES; // You can edit _ picker. delegate = self; // sets proxy, detection operation} return _ picker;} // video player-(MPMoviePlayerController *) moviePlayer {if (! _ MoviePlayer) {_ moviePlayer = [MPMoviePlayerController new]; _ moviePlayer. view. frame = self. imgView. frame; _ moviePlayer. view. autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self. movieView = _ moviePlayer. view; [self. view addSubview: self. movieView];} _ moviePlayer. contentURL = self. movieUrl; return _ moviePlayer;} // photograph and video recording: tag = 0 indicates taking a photo, and = 1 indicates recording a video-(IBAction) openVid Eo :( UIButton *) sender {if (self. currentTag! = Sender. tag) self. isChange = YES; self. currentTag = sender. tag; [self presentViewController: self. picker animated: YES completion: nil] ;}# pragma mark-proxy method-(void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info {NSString * mediaType = [info objectForKey: UIImagePickerControllerMediaType]; if ([mediaType isEqualToString :( NSString *) kUTTypeImage]) {// UIImage * image when taking a photo; // if editing is allowed, the edited image is obtained; otherwise, the original image is obtained if (self. picker. allowsEditing) {image = [info objectForKey: Photo]; // get the edited photo} else {image = [info objectForKey: UIImagePickerControllerOriginalImage]; // obtain the original photo} [self. imgView setImage: image]; // display photo // UIImageWriteToSavedPhotosAlbum (image, nil); // Save the photo to the album} else if ([mediaType is1_tostring :( NSString *) kUTTypeMovie]) {// when the video is being recorded, NSURL * url = [info objectForKey: UIImagePickerControllerMediaURL]; // The video path NSString * urlStr = [url path]; //// Save the video to the album // if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (urlStr) {// UISaveVideoAtPathToSavedPhotosAlbum (urlStr, self, nil, nil ); // Save the video to the album //} self. movieUrl = [NSURL fileURLWithPath: urlStr]; [self. moviePlayer play];} // close the photo selector [self dismissViewControllerAnimated: YES completion: nil];}View Code

 

Download DEMO:

Github address: https://github.com/xiaotanit/Tan_LocationPhotoVideo

 

Link: http://www.cnblogs.com/tandaxia/p/5507154.html

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.