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 ->

// 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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to