ARSPopover icon indicating copy to clipboard operation
ARSPopover copied to clipboard

Auto Layout support?

Open kenmhaggerty opened this issue 8 years ago • 2 comments

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.

kenmhaggerty avatar Apr 06 '16 12:04 kenmhaggerty

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.

soberman avatar Apr 13 '16 17:04 soberman

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:.

kientux avatar Feb 14 '17 16:02 kientux