adit
adit

Reputation: 33674

UIView to stick at bottom of UIScrollView

So I have a UIScrollView inside a UIView of a UIViewController in which I added a UIView inside it, and I wanted it to always stick at the bottom regardless of the orientation changes. So I had the following:

enter image description here

The issue is that when I rotate into landscape, the scroll view content size height is definitely going to be bigger than the frame height, and therefore it scrolls down. However this UIView that I want to stick at the bottom doesn't stick. How do I make it so that it always stick to the bottom regardless of the orientation changes.

When I disabled UIScrollView autoresize subviews, this UIView sticks to the bottom, but the width doesn't adjust when rotated

Upvotes: 2

Views: 1998

Answers (2)

MPG
MPG

Reputation: 251

You should try to use auto-resizing mask in the following manner

yourview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

using the coding or in IB add the top, left, bottom, and right margin flexibility.

or otherwise place view as per your requirement in willRotateToInterfaceOrientation method.

Upvotes: 2

TheTiger
TheTiger

Reputation: 13364

You will have to adjust frame according to orientations see below example -

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        //set your portrait frame here and also the content size of scrollView
    }
    else
    {
        //set your Landscape frame here and also the content size of scrollView
    } 
}

Upvotes: 1

Related Questions