• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 尝试预加载谷歌地图 View

[复制链接]
菜鸟教程小白 发表于 2022-12-13 09:08:59 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在导航 Controller 内的 View Controller 中有一个谷歌地图 View ,该导航 Controller 位于标签栏 Controller 上。一切正常,但当我最初点击“ map ”选项卡时, map 上的加载时间为 5-10 秒。

storyboard-layout

我遇到过几篇 StackOverflow 帖子,其中列出了以下预加载选项卡的方法:

for (UIViewController *viewController in self.tabBarController.viewControllers)
{
    [viewController view];
}

我已将其修改为我的特定实现。

for (UIViewController *viewController in self.tabBarController.viewControllers)
{
    UINavigationController *navCon = (UINavigationController*)viewController;
    for (UIViewController *vc in navCon.viewControllers) {
        if ([[NSString stringWithFormat"%@",vc.class]  isEqual: @"MapViewController"]){
            MapViewController *mv = (MapViewController*) vc;
            [mv view];
        }

    }
}

不幸的是,这两种实现都没有预加载 map 选项卡。

规范

  • 谷歌地图 SKD 1.7.2
  • iOS SDK 7.1

编辑 MapViewController.m 上的 ViewDidLoad

- (void)viewDidLoad
{
    [super viewDidLoad];
    mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:nil];
    mapView_.delegate = self;
    AppDelegate *appDelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
    CLLocationCoordinate2D loc=appDelegate.locationManager.location.coordinate;

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:loc.latitude
                                                            longitude:loc.longitude
                                                                 zoom:12];
    [mapView_ setCamera:camera];
    mapView_.myLocationEnabled=YES;
    mapView_.settings.myLocationButton = YES;
    self.view = mapView_;
}



Best Answer-推荐答案


我建议只使用容器 View (长 how-to ),这很容易;然后它将可靠地独立工作。如果您愿意,只需在加载时将其移出屏幕即可(也许之后将其滑入)。

请注意,在容器 View 中,假设“父级”属于 Boss 类,

@implementation SomeContaineredView
-(void)allTheDataLoaded
    {
    [(Boss*)self.parentViewController someMethodInBoss];
    }
@end

与父类对话就是这么简单。


注意 - 如果您需要 从父 View 到容器 View ,如果您知道 Apple 让您做的“愚蠢的把戏”,这将非常容易.. https://stackoverflow.com/a/15706092/294884

这有点古怪,对于这样一个基本的操作,你一直都做得很好。你在 prepareForSegue 中这样做:像这样......

-(void)prepareForSegueUIStoryboardSegue *)segue senderid)sender
    {
    if ([segue.identifier isEqualToString"containerLogin"])
        self.vcLogin = (LoginVC *)segue.destinationViewController;

    if ([segue.identifier isEqualToString"containerStartNew"])
        self.vcStartNew = (StartNewVC *)segue.destinationViewController;

    }

在示例中,有两个容器 View 。 (使用标识符“containerLogin”和“containerStartNew”)所以,我有两个属性(self.vcLogin、self.vcStartNew)。这正是您设置它们的方式。

请注意,prepareForSegue 名称错误。它应该被称为 “当你有一个嵌入 segue 时运行的设置” 我在这里详细解释一下:https://stackoverflow.com/a/24351813/294884

重要! ...

这是一个方便的宏!!!

#define seg(A, B, C) if ([segue.identifier isEqualToString:A]) \
                           B = (C *)segue.destinationViewController;

在我们从事的每个项目中,我们都会使用该宏。

那么你就可以这么写了:

-(void)prepareForSegueUIStoryboardSegue *)segue senderid)sender
    {
    seg(@"cOverlayBuy", self.rockets, Rockets);
    seg(@"cOverlayMainMenu", self.overlayMainMenu, OverlayMainMenu);
    
    seg(@"cSearch", self.search, Search);
    seg(@"cMeeting", self.meeting, Meeting);
    
    seg(@"cMeetings", self.meetings, Meetings);
    seg(@"cBooks", self.bikes, Bikes);
    seg(@"cPeople", self.cars, Cars);
    }

因为,如今,每个场景都有许多容器 View ,我们拥有的每个场景,对于每个客户,在“prepareForSegue”调用中都有该代码。

因此,一旦该代码运行,您终于可以“访问您的容器 View !”

[self.cars displayColors"red"];
self.cars.view.hidden=YES;
[self.meetings calculateNewTimesNow];

...等等。

就像我说的,我们在每个项目中都使用这个宏。现在几乎每个场景都有一些容器 View ,所以它在每个 VC 中!希望它可以帮助某人。

关于ios - 尝试预加载谷歌地图 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25985186/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap