Last active
August 29, 2015 14:16
-
-
Save nolili/9aeadf285528a44c2e41 to your computer and use it in GitHub Desktop.
MapView Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// DropPinStudy | |
// | |
// Created by nori on 2015/03/04. | |
// Copyright (c) 2015年 Noritaka Kamiya. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface NRUtility:NSObject | |
@end | |
@implementation NRUtility | |
+ (CGFloat)degreeToRadian:(CGFloat)degrees | |
{ | |
return degrees * (M_PI / 180.0); | |
} | |
+ (CGFloat)radianToDegree:(CGFloat)radians | |
{ | |
return radians * (180 / M_PI); | |
} | |
@end | |
@interface ViewController () <MKMapViewDelegate> | |
@property (nonatomic, weak) IBOutlet MKMapView *mapView; | |
@property (nonatomic, assign) CLLocationCoordinate2D appleHQCoordinate; | |
@property (nonatomic, strong) MKAnnotationView *annotationView; | |
@property (nonatomic, strong) MKPointAnnotation *pointAnnotation; | |
@property (nonatomic, assign) CGFloat angle; // degreeで指定してちょ | |
@end | |
@implementation ViewController | |
- (instancetype)initWithCoder:(NSCoder *)coder | |
{ | |
self = [super initWithCoder:coder]; | |
if (self) { | |
_appleHQCoordinate = CLLocationCoordinate2DMake(37.33072, -122.029674); | |
_pointAnnotation = [[MKPointAnnotation alloc] init]; | |
_pointAnnotation.coordinate= _appleHQCoordinate; | |
_angle = 120; | |
} | |
return self; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// ベースビューのサイズを合わせておきましょう。 | |
_mapView.frame = (CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.height)); | |
_mapView.center = self.view.center; | |
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(rotate) userInfo:nil repeats:NO]; | |
} | |
- (void)rotate | |
{ | |
CGFloat degree = _angle; | |
NSLog(@"%f 度回転するよ", degree); | |
// 回転は右回り | |
_mapView.transform = CGAffineTransformMakeRotation([NRUtility degreeToRadian:_angle]); | |
} | |
- (void)viewDidAppear:(BOOL)animated | |
{ | |
[super viewDidAppear:animated]; | |
[_mapView addAnnotation:_pointAnnotation]; | |
MKCoordinateSpan span = MKCoordinateSpanMake(1, 1); | |
[_mapView setCenterCoordinate:_appleHQCoordinate animated:YES]; | |
[_mapView regionThatFits:MKCoordinateRegionMake(_appleHQCoordinate, span)]; | |
} | |
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views | |
{ | |
} | |
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation | |
{ | |
if (self.annotationView == nil){ | |
self.annotationView = [[MKAnnotationView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; | |
self.annotationView.backgroundColor = [UIColor redColor]; | |
self.annotationView.image = [UIImage imageNamed:@"CoursePosition"]; | |
self.annotationView.transform = CGAffineTransformMakeRotation([NRUtility degreeToRadian:-(_angle)]); | |
} | |
return self.annotationView; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment