• 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
Re: Updated View Bounds After Orientation Change...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updated View Bounds After Orientation Change...


  • Subject: Re: Updated View Bounds After Orientation Change...
  • From: David Duncan <email@hidden>
  • Date: Sun, 25 Oct 2015 10:11:56 -0700

> On Oct 24, 2015, at 8:45 PM, Peters, Brandon <email@hidden> wrote:
>
> Devs,
>
> I have a UIStackView, which holds an image view and a text view. The image view has an activity indicator view as a subview (I add this programmatically). When the view initially view loads, I center the activity indicator view within the image view and starting the animation for the AIV. But, in the process of waiting for the image to load, if I rotate the image view, the AIV needs to be re-centered. I added code to listen for the status bar orientation change notification, and have a method to invoke upon the notification (UIApplicationDidChangeStatusBarOrientationNotification). In that method, I attempt to get the bounds of the image view and use that to re-center the AIV within the image view. But, it seems that the value of the bounds of the image view is not changing when the device orientation changes. Is there a “reliable" way to get the updated bounds for a view after the device orientation has changed? Code ->

Why do all this at all? Just add 2 constraints that tie the center of the activity indicator to its superview and it will remain centered always.

[_activityIndicator.centerXAnchor constraintEqualToAnchor:_imageView.centerXAnchor].active = YES;
[_activityIndicator.centerYAnchor constraintEqualToAnchor:_imageView.centerYAnchor].active = YES;

(or equivalent if you need to support prior to iOS 9).

>
> // start listening for orientation changes
>            NSNotificationCenter.defaultCenter().addObserver(self, selector: "orientationDidChange:",
>                name: UIApplicationDidChangeStatusBarOrientationNotification, object: nil)
> …
>  func orientationDidChange(notification: NSNotification) {
>
>        // get image view bounds
>        let viewBounds = _imageView.bounds
>
>        // recenter the activity indicator
>        _activityIndicator.center = CGPointMake(CGRectGetMidX(viewBounds), CGRectGetMidY(viewBounds))
>
>    }
>
> _______________________________________________
>
> 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

--
David Duncan


_______________________________________________

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


References: 
 >Updated View Bounds After Orientation Change... (From: "Peters, Brandon" <email@hidden>)

  • Prev by Date: Re: Hide UINavigationBar and keep UIPageController content static
  • Next by Date: Re: NSSplitView in a separate NSWindowControl doesn't show for some reason
  • Previous by thread: Updated View Bounds After Orientation Change...
  • Next by thread: Re: Updated View Bounds After Orientation Change...
  • Index(es):
    • Date
    • Thread