> On Oct 24, 2015, at 8:45 PM, Peters, Brandon <bap...@my.fsu.edu> 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 (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com > > This email sent to david.dun...@apple.com -- David Duncan _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com