Right, activate and deactivate are not animatable, but the constant values in constraints are.
True, it depends on what you’re showing as to whether to shrink or move your view. When I wanted to use a search bar in UISearchController with a collection view in iOS to appear similarly as UITableView, I moved the search bar: https://whatweretheythinkingblog.wordpress.com/2016/11/19/effectively-using-uisearchcontroller-with-uicollectionview/ When I wanted to show an icon to the left of a title, where the item may not have an icon but was only available through a REST call, I found it more attractive to grow the icon and compress the title in that animation, choosing a scale-to-fill option, when I determined there was an icon. -- Gary L. Wade http://www.garywade.com/ <http://www.garywade.com/> > On Dec 14, 2016, at 2:52 PM, Doug Hill <cocoa...@breaqz.com> wrote: > > Gary, > > Thanks for the reply. > I tried moving the container rather than resizing to 0 because there's a > table inside this view and it will relayout when resizing. For an animation, > I guess it depends on what effect you want: either seeing the view move or > resize to 0. > > Oddly, when I put my code to activate/deactivate constraints inside a [UIView > animateWithDuration…] I get no animation. :( > > Doug Hill > >> On Dec 14, 2016, at 2:49 PM, Gary L. Wade <garyw...@desisoftsystems.com >> <mailto:garyw...@desisoftsystems.com>> wrote: >> >> If I understand you correctly, you might prefer the approach I chose to do. >> Rather than activating and deactivating constraints (BTW, you should always >> deactivate before having multiple actives), set your constraints up to >> always be active but change the width for the one you’re hiding to 0 and the >> other to be the extra size needed to fill the gap. I also chose to animate >> the constant values, so the size-change is smooth to the user. >> -- >> Gary L. Wade >> http://www.garywade.com/ <http://www.garywade.com/> >>> On Dec 14, 2016, at 2:19 PM, Doug Hill <cocoa...@breaqz.com >>> <mailto:cocoa...@breaqz.com>> wrote: >>> >>> I'm seeing warnings in the console when I dynamically make autolayout >>> constraints active/inactive at runtime. >>> >>> I have two constraints that align a container view leading or trailing edge >>> with another view's edge. This is to move the container onscreen or >>> offscreen. I have another view whose trailing edge aligns with the leading >>> edge of the first container view so it moves with it as autolayout >>> constraints change. >>> >>> At runtime, I make one of these constraints active and the other inactive, >>> like so: >>> >>> - (IBAction)toggleCommentsVisibility:(id)sender >>> { >>> self.commentsAreHidden ? [self showComments:self] : [self >>> hideComments:self]; >>> } >>> >>> - (IBAction)showComments:(id)sender >>> { >>> self.showCommentsConstraint.active = YES; >>> self.hideCommentsContainerConstraint.active = NO; >>> >>> self.commentsAreHidden = NO; >>> } >>> >>> - (IBAction)hideComments:(id)sender >>> { >>> self.showCommentsConstraint.active = NO; >>> self.hideCommentsContainerConstraint.active = YES; >>> >>> self.commentsAreHidden = YES; >>> } >>> >>> When I call showComments, I get the following warning in the console: >>> >>> ===== >>> >>> 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. >>> ( >>> "<NSLayoutConstraint:0x7f91426a3ef0 'CommentContainerProportionalWidth' >>> UIView:0x7f91426d9db0.width == 0.33*UIView:0x7f91426def30.width>", >>> "<NSLayoutConstraint:0x7f91426c91e0 'Hide Comments Constraint' >>> H:[UIView:0x7f91426d7f00]-(0)-[UIView:0x7f91426d9db0]>", >>> "<NSLayoutConstraint:0x7f91426e2990 'ShowComments' >>> UIView:0x7f91426d9db0.trailing == UIView:0x7f91426d7f00.trailing>", >>> "<NSLayoutConstraint:0x7f91427e43c0 'UIView-Encapsulated-Layout-Width' >>> H:[UIView:0x7f91426def30(768)]>" >>> ) >>> >>> Will attempt to recover by breaking constraint >>> <NSLayoutConstraint:0x7f91426c91e0 'Hide Comments Constraint' >>> H:[UIView:0x7f91426d7f00]-(0)-[UIView:0x7f91426d9db0]> >>> >>> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to >>> catch this in the debugger. >>> >>> ===== >>> >>> This is puzzling because IB doesn't give me any autolayout errors/warning >>> when I manually activate/deactivate these constraints. Also, I don't get >>> this runtime warning when calling hideComments, only the 'show' case. >>> Finally, things actually work at runtime because it's nice enough to >>> "break" the constraint that I deactivated in code. But I would like to not >>> have these warnings. >>> >>> Any ideas on what's going on how I might go about debugging this? >>> >>> Doug Hill >>> _______________________________________________ >>> >>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com >>> <mailto: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 >>> <http://lists.apple.com/> >>> >>> Help/Unsubscribe/Update your Subscription: >>> https://lists.apple.com/mailman/options/cocoa-dev/garywade%40desisoftsystems.com >>> >>> <https://lists.apple.com/mailman/options/cocoa-dev/garywade%40desisoftsystems.com> >>> >>> This email sent to garyw...@desisoftsystems.com >>> <mailto:garyw...@desisoftsystems.com> >> > _______________________________________________ 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