简体   繁体   中英

Constraint Change on Screen Tap

I use the code below to expand an image header to it's full size when the user taps on the screen. This works perfectly in iOS 8. However, it does nothing at all in iOS 7. ie changing the constraint does nothing. However, changing the same constraint in viewDidLayoutSubviews (on initial load) works fine in iOS 7 too. What could be happening here? Any help would be much appreciated. contentView is connected to the top level view of the view controller.

-(IBAction) tapScreen:(id)sender {
    if (!expanded)
    {
        if ([self.topSize constant] < correctImageViewHeight+self.topLayoutGuide.length)
        [self.topSize setConstant:correctImageViewHeight+self.topLayoutGuide.length];
        expanded = YES;

    }
    else
        {
        [self.topSize setConstant:self.view.bounds.size.height/2.0f];
            expanded = NO;
        }
    [UIView animateWithDuration:0.4
                     animations:^{
                         [self.contentView layoutIfNeeded];
                     }];

}

Actually figured out what was going on minutes after posting the question. I was re-setting the constraint in viewDidLayoutSubViews, which for some reason does not get called again for the constraint change in iOS 8 but is called in iOS 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM