Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Layout support? #12

Open
kenmhaggerty opened this issue Apr 6, 2016 · 2 comments
Open

Auto Layout support? #12

kenmhaggerty opened this issue Apr 6, 2016 · 2 comments

Comments

@kenmhaggerty
Copy link

As a very simple sample I'm trying to display a multi-line UILabel in an ARSPopover using Auto Layout to break it into multiple lines and to ensure that the popover's content size fits within the screen:

    ARSPopover *popover = [ARSPopover new];
    popover.sourceView = sourceView;
    popover.sourceRect = CGRectMake(CGRectGetMidX(sourceView.bounds), CGRectGetMaxY(sourceView.bounds), 0.0f, 0.0f);
//    popover.contentSize = CGSizeMake(200.0f, 100.0f);
    popover.arrowDirection = UIPopoverArrowDirectionUp;

    [popover insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
        UILabel *label = [[UILabel alloc] init];
        label.text = @"This is a tutorial view! Let's see if this works properly.";
        label.numberOfLines = 0;
        label.textAlignment = NSTextAlignmentLeft;
        [label sizeToFit];
        [popover.view addSubview:label];

        [popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeLeftMargin multiplier:1.0f constant:0.0f]];
        [popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeRightMargin multiplier:1.0f constant:0.0f]];
        [popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeTopMargin multiplier:1.0f constant:0.0f]];
        [popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeBottomMargin multiplier:1.0f constant:0.0f]];

        [popover.view setNeedsUpdateConstraints];
        [popover.view layoutIfNeeded];
    }];

    [self presentViewController:popover animated:YES completion:nil];

However it doesn't seem like ARSPopover supports Auto Layout.

@soberman
Copy link
Owner

In case you want to use AutoLayout, then you should do layout configurations after you call [self presentViewController:popover animated:YES completion:nil];. I know it sounds strange, but Apple advises to do it in such manner.

@kientux
Copy link

kientux commented Feb 14, 2017

This issue is old but, as I see ARSPopover is just a subclass of UIViewController which automatically set its modalPresentationStyle to popover. So you can just subclass ARSPopover and set up your views with auto layout like normal view controller, without the need of calling -insertContentIntoPopover:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants