cutting-room-floor / mapbox-gl-cocoa

OBSOLETE
74 stars 12 forks source link

White screen on build #58

Closed gijs closed 10 years ago

gijs commented 10 years ago

Hi,

I'm using the dynamic framework (build target ios8) but I'm getting a white screen on Build & Run:

screen shot 2014-10-14 at 22 28 00

I've followed these instructions and I'm running XCode 6.0.1 on Mavericks.

Did I miss something? I'm new to iOS development so it's probably something obvious.

Thx!

incanus commented 10 years ago

Without having set autolayout constraints on your map view, I'm guessing that because of iOS 8+ behavior, your view isn't resizing properly at viewWillAppear: and later. You can confirm this by setting up that method and setting a breakpoint, then p mapView.frame, which will likely be CGRectZero. Or you can set a different color for self.view.backgroundColor and see if the all-white changes to it instead, meaning your map view isn't visible.

To fix, try something like this in your viewDidLoad:

mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

This old-style way of setting masks should get auto-converted to constraints and keep your map view the same size as the root view.

gijs commented 10 years ago

Thx!

Setting self.view.backgroundColor = [UIColor greenColor]; indeed turns the screen to green, but the autoresizingMask doesn't fix the sizing of the map. I'll try some more tomorrow...

gijs commented 10 years ago

Hmm, can't figure it out... If anyone has hints that would be great. (I'm going to read some iOS8 tutorials in the meantime :))

//
//  ViewController.m
//  Lizard
//
//  Created by Gijs Nijholt on 14/10/14.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)
                                                accessToken:@"pk.eyJ1IjoibmVsZW5zY2h1dXJtYW5zIiwiYSI6ImhkXzhTdXcifQ.3k2-KAxQdyl5bILh_FioCw"];

    [mapView setCenterCoordinate:CLLocationCoordinate2DMake(28.369334, -80.743779)
                       zoomLevel:13
                        animated:NO];

    [mapView useBundledStyleNamed:@"outdoors"];

//    [self.view setAutoresizesSubviews:YES];
//    [mapView setAutoresizingMask:( UIViewAutoresizingFlexibleWidth |
//                                        UIViewAutoresizingFlexibleHeight )];

    [self.view addSubview:mapView];
//    NSLog(@" data %@", mapView);
    [self.view bringSubviewToFront:mapView];

}

- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    self.parentViewController.view.frame = self.view.bounds;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

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

@end
incanus commented 10 years ago

Going to close for now since this isn't specific to Mapbox GL, but feel free to post back @gijs with anything you find for completeness here.

gijs commented 10 years ago

Will do. Thx for now!