2013-12-15 4 views
-1

Google지도에 여러 개의지도 뷰가 있습니다. 사용자가 맵, 위성, 하이브리드 맵을 선택할 수 있도록 간단한 세그먼트 컨트롤러 스위치를 추가하려고합니다. 모든 지시 사항은 Google지도와 관련이있는 것 같습니다. Apple mapkit을 사용하고 있습니다.사과 맵 맵 맵 스타일 - 분할 된 컨트롤러를 사용하여 스타일 변경 구현

업데이트]

.H 파일

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 

@interface TrucksViewController : UIViewController { 

} 

- (IBAction)setMap:(id)sender; 

@property (weak, nonatomic) IBOutlet MKMapView *myMapView; 
@property (weak, nonatomic) IBOutlet UISegmentedControl *mapType; 

@end 

하는 .m 파일

여기
#import "TrucksViewController.h" 

@interface TrucksViewController() 


@end 

@implementation TrucksViewController 
@synthesize myMapView; 

#pragma mark - 
#pragma mark Initialisation 

- (id)initWithCoder:(NSCoder *)aDecoder { 
self = [super initWithCoder:aDecoder]; 
if (self) { 
    // Set the title for this view controller 
    // Note: In future we will copy over the title from any created  UINavigationBar objects 
    self.title = @"Trucks"; 

    [[UIApplication sharedApplication] setStatusBarHidden:NO  withAnimation:UIStatusBarAnimationNone]; 
} 
return self; 
} 

#pragma mark - 
#pragma mark UIViewController Delegates 

- (IBAction)setMap:(id)sender { 

switch (((UISegmentedControl *) sender).selectedSegmentIndex) { 
    case 0: 
     myMapView.mapType = MKMapTypeStandard ; 
     break; 
    case 1: 
     myMapView.mapType = MKMapTypeSatellite ; 
     break; 
    case 2: 
     myMapView.mapType = MKMapTypeHybrid ; 
     break; 

    default: 
     break; 
} 
} 

- (void)didReceiveMemoryWarning { 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (void)viewDidUnload { 
[super viewDidUnload]; 
} 

-(void)viewWillAppear:(BOOL)animated { 
[super viewWillAppear:animated]; 

// Update support iOS 7 
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { 
    self.edgesForExtendedLayout = UIRectEdgeNone; 
    self.navigationController.navigationBar.translucent = NO; 
} 
} 

-(void)viewWillDisappear:(BOOL)animated { 
[super viewWillDisappear:animated]; 

// Revert to default settings 
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { 
    self.edgesForExtendedLayout = UIRectEdgeAll; 
} 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 


@end 

답변

0

당신은 사람이 ..

은 다음과 같이 당신의 .H 파일에 IBAction를 선언 이동 :

- (IBAction)setMap:(id)sender; 

.m 파일에 세그먼트 화 된 컨트롤러가있는 메서드를 만듭니다.

- (IBAction)setMap:(id)sender { 

switch (((UISegmentedControl *) sender).selectedSegmentIndex) { 
    case 0: 
     myMapView.mapType = MKMapTypeStandard ; 
     break; 
    case 1: 
     myMapView.mapType = MKMapTypeSatellite ; 
     break; 
    case 2: 
     myMapView.mapType = MKMapTypeHybrid ; 
     break; 

    default: 
     break; 
} 
} 

ib에 세그먼트 컨트롤을 연결하는 것을 잊지 마십시오. 또한 위에는 세 개의 세그먼트가 있으므로 개체 라이브러리의 세그먼트 화 된 컨트롤에는 기본적으로 두 개가 있으므로 세 번째 세그먼트를 직접 추가해야합니다.

+0

수정 된 .h 및 .m 파일을 추가했습니다. 아직도 뭔가 빠져 .... – pinhead