iOS 开发

我的iOS入门第三课

2016-09-20  本文已影响250人  __西门吹雪__

简介

承上两篇我的iOS入门第一课我的iOS入门第二课,本次记录的是一年前写的MyLocations,当时是用swift,前几天用OC重写了一遍,感触良多。主要功能是记录个人走过的地方,加以描述和照片在手机里留下美好的记忆。如下:

主要界面.png

下面主要讲我学到了什么:

一、基本控件
UITableView,MKMapView
二、框架
CoreLocation、CoreData、MapKit、CoreGraphics、CoreAnimation、AudioToolbox

重点知识:

CLAuthorizationStatus authStatus = [CLLocationManager authorizationStatus];
    if (authStatus == kCLAuthorizationStatusNotDetermined) {
        [_locationManager requestWhenInUseAuthorization];
        return;
    }
    if (authStatus == kCLAuthorizationStatusDenied || authStatus == kCLAuthorizationStatusRestricted) {
        [self showLocationServicesDeniedAlert];
        return;
    }

并在info.plist中加上

key:NSLocationWhenInUseUsageDescription 
type:String 
value:This app lets you keep track of interesting places. It needs access to the GPS coordinates for your location. 
UIImagePickerController *imagePicker = [[MyImagePickerController alloc] init];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; // PhotoLibrary为相册
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    imagePicker.view.tintColor = self.view.tintColor;
    [self presentViewController:imagePicker animated:YES completion:nil];
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    _image = info[UIImagePickerControllerEditedImage];//取得照片
    if (_image) {
        [self showImage:_image];
    }
    [self.tableView reloadData];
    [self dismissViewControllerAnimated:YES completion:nil];   
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
}
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.userLocation.coordinate, 1000, 1000); // 1000米的度量
    [self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];

总结

此app是对tableView使用的进一步加强,还有对CoreData的认识和使用,并且还有对CoreLocation和MapView的理解,初涉CoreAnimation之CABasicAnimation,等等。细节的处理、熟悉api,精密的逻辑,让我对iOS开发又上升了一个层次。不说了,继续加油!
源代码传送门

卧薪藏胆,三千越甲可吞吴。

上一篇 下一篇

猜你喜欢

热点阅读