Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
5020
IGSlideTabView + Auto Layout = CALayerInvalidGeometry Crash
posted

Taking this IGSlideTabView code from the dev guide:

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    self.view.backgroundColor = [UIColor purpleColor];

    IGSlideTabView *slideTabView = [[IGSlideTabView alloc] init];

    slideTabView.frame = self.view.bounds;

    slideTabView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;    

    [self.view addSubview:slideTabView];    

    IGSlideTabItem *slideTabItem = [IGSlideTabItem tabWithLocation:IGSlideTabLocationBottom

                                                             title:@"Getting Started"

                                                           tabView:nil

                                                       contentView:nil];

    slideTabItem.contentSize = [IGSlideTabContentSize sizeWithWidth:200 height:200];

    

    [slideTabView addTab:slideTabItem];

}

and converting to auto layout...

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor purpleColor];

    

    IGSlideTabView *slideTabView = [[IGSlideTabView alloc] init];

    [self.view addSubview:slideTabView];

    slideTabView.SE_autoLayoutEnabled = YES;

    [slideTabView SE_constrainToSuperviewAxisWithInset:CGSizeMake(0, 0) priority:1000];

    IGSlideTabItem *slideTabItem = [IGSlideTabItem tabWithLocation:IGSlideTabLocationBottom

                                                             title:@"Getting Started"

                                                           tabView:nil

                                                       contentView:nil];

    

    slideTabItem.contentSize = [IGSlideTabContentSize sizeWithWidth:200 height:200];

    

    [slideTabView addTab:slideTabItem];

}

causes crash...

'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 457.5]'

*** First throw call stack:

(

0   CoreFoundation                      0x01a461e4 __exceptionPreprocess + 180

1   libobjc.A.dylib                     0x015938e5 objc_exception_throw + 44

2   CoreFoundation                      0x01a45fbb +[NSException raise:format:] + 139

3   QuartzCore                          0x018a3e1a _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 190

4   QuartzCore                          0x018a3fd9 -[CALayer setPosition:] + 68

5   QuartzCore                          0x018a46df -[CALayer setFrame:] + 799

6   UIKit                               0x002aeb4d -[UIView(Geometry) setFrame:] + 302

7   XXXXXXXXX               0x0000d432 -[IGSlideTabView updateHorizontalTabLocation:] + 761

Parents
  • 4940
    Verified Answer
    Offline posted

    This crash comes from the fact the subview constraints aren't yet calculated in the viewDidLoad override, which results in a frame equal to CGRectZero. When using autolayout, you want to move any code that deals with frame setting (in this case, the IGSlideTabItem) to viewDidLayoutSubviews or viewDidAppear. The viewDidLayoutSubviews method is called once autolayout has finished calculating the constraints and puts the subviews in place.

    @interface ViewController ()
    {
        IGSlideTabView *_slideTabView;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.view.backgroundColor = [UIColor purpleColor];
    
        _slideTabView = [[IGSlideTabView alloc] init];
        [self.view addSubview:_slideTabView];
    
        _slideTabView.SE_autoLayoutEnabled = YES;
        [_slideTabView SE_constrainToSuperviewAxisWithInset:CGSizeMake(0, 0) priority:1000];
    }
    
    - (void)viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
    
        IGSlideTabItem *slideTabItem = [IGSlideTabItem tabWithLocation:IGSlideTabLocationBottom
                                                                 title:@"Getting Started"
                                                               tabView:nil
                                                           contentView:nil];
        slideTabItem.contentSize = [IGSlideTabContentSize sizeWithWidth:200 height:200];
        [_slideTabView addTab:slideTabItem];
    }
    
    @end
    
Reply Children
No Data