Align UIImageView to bottom of UIScrollView

I want to align the red image at the bottom of the scroll. In portrait orientation, it looks great, since the scroll height is equal to the viewing height.

Potrait orientation

But in landscape mode it looks like when in landscape I want it to be completely hidden until the user scrolls to the bottom of the scroll, so that the red image is always at the bottom of the scroll. Currently it looks in landscape mode.

Landscape orientation

I added a red image as a scrollview subquery and applied basommarginautoresizingmask to it.

+4
source share
6 answers

autoresizing, left, right, bottom flexibleWidth UIImageView, UIScrollView. .

UIScrollView , it, UIImageView , .

, .

enter image description hereenter image description here

:

Portrait

Landscape

+4

Autoresizingmask , . AutoLayout translatesAutoresizingMaskIntoConstraints , . YES , . . AutoLayout, . AutoLayout .

, , IB. AutoLayout . . . . . IB, , . IBOutlet, . , . :

@interface ViewController ()

@property (nonatomic, weak) UIImageView *imageView; // the image view
@property (nonatomic, weak) NSLayoutConstraint *imageBottomToScrollView; // the constraint you added in IB to the image view

@end

@implementation ViewController


- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(orientation)) {
        self.imageBottomToScrollView.constant = -CGRectGetHeight(self.imageView.frame);
    } else if (UIDeviceOrientationIsPortrait(orientation)) {
        self.imageBottomToScrollView.constant = 0;
    }
}


@end

~

+4

.

-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    CGSize contentSize = self.scrollView.contentSize;
    CGRect frame = self.imageView.frame;
    frame.origin.x = 0;
    frame.size.width = self.scrollView.frame.size.width;
    frame.size.height = Expected_Height;
    frame.origin.y = contentSize.height - frame.size.height;
    self.imageView.frame = frame;
}
+3

Autoresizingmask , IB, , .

+2

IB, . , , , screen_height + abs(tabbar_height - imageview_height).

+1

uiimageview scrollview, . ,

enter image description here

0

All Articles