• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem with setNeedsLayout and layoutSubviews in UIScrollView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with setNeedsLayout and layoutSubviews in UIScrollView


  • Subject: Problem with setNeedsLayout and layoutSubviews in UIScrollView
  • From: Tales Pinheiro de Andrade <email@hidden>
  • Date: Sun, 26 Jun 2011 15:39:18 -0300

Hi.

I have a few custom views of three kind inside a custom UIScrollview. I'm trying to resize these custom views as the device change the orientation.

I added these custom views programatically to the custom UIScrollView. I implemented in the custom UIScrollview the below method

- (void)layoutSubviews {
    UIDeviceOrientation currentOrientation =  [[UIDevice currentDevice] orientation];
    if (UIDeviceOrientationIsLandscape(currentOrientation)) {
        for (id view in [self subviews]) {
            if ([view isKindOfClass:[ECIndexComponent class]] ||
                [view isKindOfClass:[ECListComponent class]] ||
                [view isKindOfClass:[ECGraphView class]]) {

                CGRect newFrame = [(UIView *)view frame];
                newFrame.size.width *= 1.5;
                newFrame.size.height *= 1.5;
                newFrame.origin.y *= 1.5;
                [(UIView *)view setFrame:newFrame];
            }
        }
    }
    else {
        for (id view in [self subviews]) {
            if ([view isKindOfClass:[ECIndexComponent class]] ||
                [view isKindOfClass:[ECListComponent class]] ||
                [view isKindOfClass:[ECGraphView class]]) {
                CGRect newFrame = [(UIView *)view frame];
                newFrame.size.width *= 0.666;
                newFrame.size.height *= 0.666;
                newFrame.origin.y *= 0.666;
                [(UIView *)view setFrame:newFrame];
            }
        }

    }
}

And in my view controller shouldAutorotateToInterfaceOrientation method I call setNeedsLayout for the custom scroll view. It's almost there, but now, when I try to scroll, these subviews get redimensioned, even if I did not changed the orientation. It looks like the scrolling is calling layoutSubviews

Is there a way to correct this?

Thank you
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem with setNeedsLayout and layoutSubviews in UIScrollView
      • From: David Duncan <email@hidden>
  • Prev by Date: Re: NSURLConnection
  • Next by Date: Re: Problem with setNeedsLayout and layoutSubviews in UIScrollView
  • Previous by thread: Re: NSURLConnection
  • Next by thread: Re: Problem with setNeedsLayout and layoutSubviews in UIScrollView
  • Index(es):
    • Date
    • Thread