David,

In IB, I have a vertical UIStackView with an image view and a text view 
(stacked in that order). I add the activity indicator programmatically:

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)

        // add activity indicator and start animation
        if _useActivityIndicator == true {

            // set constraints
            _imageView.addSubview(_activityIndicator)

            
_activityIndicator.centerXAnchor.constraintEqualToAnchor(_imageView.centerXAnchor).active
 = true
            
_activityIndicator.centerYAnchor.constraintEqualToAnchor(_imageView.centerYAnchor).active
 = true

            _activityIndicator.startAnimating()
        }
    }

I get this error:

2015-10-26 22:44:42.971 Historic Sites Navigator[247:13410] Unable to 
simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't 
want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't 
understand, refer to the documentation for the UIView property 
translatesAutoresizingMaskIntoConstraints)
(
    "<NSAutoresizingMaskLayoutConstraint:0x14dbda90 h=--& v=--& 
UIActivityIndicatorView:0x14eb3760.midX == + 10>",
    "<NSLayoutConstraint:0x14dce780 H:|-(0)-[UINavigationBar:0x14dd17d0]   
(Names: '|':UIView:0x14d88e30 )>",
    "<NSLayoutConstraint:0x14d7a200 H:[UINavigationBar:0x14dd17d0]-(0)-|   
(Names: '|':UIView:0x14d88e30 )>",
    "<NSLayoutConstraint:0x14d7f660 UIStackView:0x14dbcf50.trailing == 
UINavigationBar:0x14dd17d0.trailing>",
    "<NSLayoutConstraint:0x14d81a70 UIStackView:0x14dbcf50.leading == 
UINavigationBar:0x14dd17d0.leading>",
    "<NSLayoutConstraint:0x14dca540 UIActivityIndicatorView:0x14eb3760.centerX 
== UIImageView:0x14dd16c0.centerX>",
    "<NSLayoutConstraint:0x14ea41c0 'UISV-canvas-connection' 
UIStackView:0x14dbcf50.leading == UIImageView:0x14dd16c0.leading>",
    "<NSLayoutConstraint:0x14e75910 'UISV-canvas-connection' 
H:[UIImageView:0x14dd16c0]-(0)-|   (Names: '|':UIStackView:0x14dbcf50 )>",
    "<NSLayoutConstraint:0x14e746c0 'UIView-Encapsulated-Layout-Width' 
H:[UIView:0x14d88e30(320)]>"
)

Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x14dca540 UIActivityIndicatorView:0x14eb3760.centerX == 
UIImageView:0x14dd16c0.centerX>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch 
this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed 
in <UIKit/UIView.h> may also be helpful.

I do not understand how the error is occurring.


On Oct 26, 2015, at 2:02 PM, David Duncan 
<[email protected]<mailto:[email protected]>> wrote:


On Oct 25, 2015, at 12:13 PM, Peters, Brandon 
<[email protected]<mailto:[email protected]>> wrote:

David,

I tried your suggestion, but the program terminates. I get this in the console:

view did load...
2015-10-25 15:10:57.893 Historic Sites Navigator[766:538109] *** Terminating 
app due to uncaught exception 'NSGenericException', reason: 'Unable to activate 
constraint with items <UIActivityIndicatorView: 0x145933b0; frame = (0 0; 20 
20); hidden = YES; layer = <CALayer: 0x14593220>> and <UIImageView: 0x145966c0; 
frame = (0 0; 320 208); autoresize = RM+BM; userInteractionEnabled = NO; layer 
= <CALayer: 0x145967a0>> because they have no common ancestor.  Does the 
constraint reference items in different view hierarchies?  That's illegal.’

You need to ensure they have a hierarchy relationship before activating the 
constraints – you probably didn’t add one as a subview of the other yet.

*** First throw call stack:
(0x2635c68b 0x37716e17 0x2635c5d1 0x271fa7cd 0xce7d8 0xceeb4 0x2a43821b 
0x2a43879f 0x2a755c47 0x2a86185d 0x2a7590b1 0x2a547cff 0x2a547b39 0x2a5476ad 
0x2a54724f 0x2a459535 0x2a45942f 0x29cf45a9 0x123ed73 0x1243815 0x2631f9ad 
0x2631dea7 0x26271249 0x26271035 0x2f354ad1 0x2a486899 0xc5a44 0x37e62873)
libc++abi.dylib: terminating with uncaught exception of type NSException

I will continue to work on it though. Thanks...

On Oct 25, 2015, at 1:11 PM, David Duncan 
<[email protected]<mailto:[email protected]>> wrote:


On Oct 24, 2015, at 8:45 PM, Peters, Brandon <[email protected]> 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 protected])

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 [email protected]

--
David Duncan


--
David Duncan

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to