【问题标题】:apple mapkit map style - implement style change using segmented controller [closed]苹果 mapkit 地图样式 - 使用分段控制器实现样式更改 [关闭]
【发布时间】:2013-12-15 04:55:17
【问题描述】:

我的应用中有多个地图视图。尝试添加一个简单的分段控制器开关,以使用户能够选择地图、卫星、混合地图。所有指令似乎都与谷歌地图有关;我正在使用 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

【问题讨论】:

    标签: ios maps apple-maps


    【解决方案1】:

    你来了,伙计..

    在您的 .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 中连接分段控件。上面也有三个段,所以你必须自己添加第三个,因为对象库中的分段控件默认有两个。

    【讨论】:

    • 我添加了修改后的 .h 和 .m 文件。仍然缺少一些东西......
    猜你喜欢
    • 2015-01-13
    • 2010-09-12
    • 1970-01-01
    • 2013-12-14
    • 2013-10-12
    • 1970-01-01
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多