Re: Animating autolayout constraint changes for subviews

2017-01-03 Thread Doug Hill
Just out of curiosity, is it feasible to override the animation of an 
animatable property to implement this? For example, generating the layer 
contents with the reflowed text for a keyframe animation as the frame size 
changes. Presumably I could do this be overriding the behavior for animating 
the frame property.
Trying to get an idea if this a good technique to try.

Doug Hill


> On Dec 30, 2016, at 11:56 AM, David Duncan  wrote:
> 
>> 
>> On Dec 30, 2016, at 11:50 AM, Doug Hill  wrote:
>> 
>> 
>>> On Dec 30, 2016, at 11:38 AM, David Duncan  wrote:
>>> 
>>> 
 On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
 
 Hi Ken,
 
 The exact behavior is that the label will resize to the new size 
 immediately and reflow the text, then the container view will animate it's 
 size change. It would be nice if both the label and the container view 
 animate at the same time.
 Also, as I mentioned, a button will exhibit the same behavior, probably 
 because it has a UILabel inside it to show the button text.
>>> 
>>> Labels (and other content provided via -drawRect:) will almost universally 
>>> behave this way without additional work on your part, as the content is 
>>> redrawn instantly at the final size. At best you might get an animation 
>>> where the content resizes into place, but more often than not, it will pop 
>>> in some undesirable way. Generally the only way to get good animations with 
>>> drawn content is to snapshot in some way and execute an custom animation 
>>> from the old to the new content (snapshotting isn’t necessarily literal 
>>> here – it can just mean creating a new label with the new content as one 
>>> example).
>> 
>> David,
>> 
>> Thanks for the info. I’m curious what system views with content are 
>> animatable. I guess UIImageView works for the snapshots. But anything with a 
>> label is out. I’ll do some tests and see what works.
> 
> They are all “animatable”, but the results are not necessarily well defined. 
> Most system controls use combinations of image views and labels for images 
> and text content, so the resizing animations are often going to be based on 
> how -drawRect: content resizes.
> 
>> 
>> Doug Hill
> 
> --
> 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

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread Doug Hill

> On Dec 30, 2016, at 11:56 AM, David Duncan  wrote:
> 
> 
>> On Dec 30, 2016, at 11:50 AM, Doug Hill  wrote:
>> 
>> 
>>> On Dec 30, 2016, at 11:38 AM, David Duncan  wrote:
>>> 
>>> 
 On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
 
 Hi Ken,
 
 The exact behavior is that the label will resize to the new size 
 immediately and reflow the text, then the container view will animate it's 
 size change. It would be nice if both the label and the container view 
 animate at the same time.
 Also, as I mentioned, a button will exhibit the same behavior, probably 
 because it has a UILabel inside it to show the button text.
>>> 
>>> Labels (and other content provided via -drawRect:) will almost universally 
>>> behave this way without additional work on your part, as the content is 
>>> redrawn instantly at the final size. At best you might get an animation 
>>> where the content resizes into place, but more often than not, it will pop 
>>> in some undesirable way. Generally the only way to get good animations with 
>>> drawn content is to snapshot in some way and execute an custom animation 
>>> from the old to the new content (snapshotting isn’t necessarily literal 
>>> here – it can just mean creating a new label with the new content as one 
>>> example).
>> 
>> David,
>> 
>> Thanks for the info. I’m curious what system views with content are 
>> animatable. I guess UIImageView works for the snapshots. But anything with a 
>> label is out. I’ll do some tests and see what works.
> 
> They are all “animatable”, but the results are not necessarily well defined. 
> Most system controls use combinations of image views and labels for images 
> and text content, so the resizing animations are often going to be based on 
> how -drawRect: content resizes.

Right, “animatable” in the sense that I won’t need to do a snapshot trick.

Working on the snapshotting now, appreciate the tips.

Doug Hill


___

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

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread David Duncan

> On Dec 30, 2016, at 11:50 AM, Doug Hill  wrote:
> 
> 
>> On Dec 30, 2016, at 11:38 AM, David Duncan  wrote:
>> 
>> 
>>> On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
>>> 
>>> Hi Ken,
>>> 
>>> The exact behavior is that the label will resize to the new size 
>>> immediately and reflow the text, then the container view will animate it's 
>>> size change. It would be nice if both the label and the container view 
>>> animate at the same time.
>>> Also, as I mentioned, a button will exhibit the same behavior, probably 
>>> because it has a UILabel inside it to show the button text.
>> 
>> Labels (and other content provided via -drawRect:) will almost universally 
>> behave this way without additional work on your part, as the content is 
>> redrawn instantly at the final size. At best you might get an animation 
>> where the content resizes into place, but more often than not, it will pop 
>> in some undesirable way. Generally the only way to get good animations with 
>> drawn content is to snapshot in some way and execute an custom animation 
>> from the old to the new content (snapshotting isn’t necessarily literal here 
>> – it can just mean creating a new label with the new content as one example).
> 
> David,
> 
> Thanks for the info. I’m curious what system views with content are 
> animatable. I guess UIImageView works for the snapshots. But anything with a 
> label is out. I’ll do some tests and see what works.

They are all “animatable”, but the results are not necessarily well defined. 
Most system controls use combinations of image views and labels for images and 
text content, so the resizing animations are often going to be based on how 
-drawRect: content resizes.

> 
> Doug Hill

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

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread Doug Hill

> On Dec 30, 2016, at 11:38 AM, David Duncan  wrote:
> 
> 
>> On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
>> 
>> Hi Ken,
>> 
>> The exact behavior is that the label will resize to the new size immediately 
>> and reflow the text, then the container view will animate it's size change. 
>> It would be nice if both the label and the container view animate at the 
>> same time.
>> Also, as I mentioned, a button will exhibit the same behavior, probably 
>> because it has a UILabel inside it to show the button text.
> 
> Labels (and other content provided via -drawRect:) will almost universally 
> behave this way without additional work on your part, as the content is 
> redrawn instantly at the final size. At best you might get an animation where 
> the content resizes into place, but more often than not, it will pop in some 
> undesirable way. Generally the only way to get good animations with drawn 
> content is to snapshot in some way and execute an custom animation from the 
> old to the new content (snapshotting isn’t necessarily literal here – it can 
> just mean creating a new label with the new content as one example).

David,

Thanks for the info. I’m curious what system views with content are animatable. 
I guess UIImageView works for the snapshots. But anything with a label is out. 
I’ll do some tests and see what works.

Doug Hill
___

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

Re: Animating autolayout constraint changes for subviews

2016-12-30 Thread David Duncan

> On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
> 
> Hi Ken,
> 
> I uploaded a sample project here:
> 
> https://github.com/djfitz/TestAutolayoutAnimations
> 
> I tried to strip this down to what is needed to show the behavior I see.
> 
> My code to actually do the animation is this:
> 
> - (IBAction)animateIt:(id)sender
> {
>   static BOOL small = NO;
> 
>   if( small )
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
>   else
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width / 2;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
> 
>   small = !small;
> }
> 
> 'container view' has one subview which is a UILabel. The label is pinned to 
> the superview edges via autolayout constraints. (e.g. trailing, leading, top, 
> bottom edges all pinned to superview edges.)
> 
> I tried a few different variations, including leaving out the first 
> layoutIfNeeded (which some people say should be done, others not).
> 
> The exact behavior is that the label will resize to the new size immediately 
> and reflow the text, then the container view will animate it's size change. 
> It would be nice if both the label and the container view animate at the same 
> time.
> Also, as I mentioned, a button will exhibit the same behavior, probably 
> because it has a UILabel inside it to show the button text.

Labels (and other content provided via -drawRect:) will almost universally 
behave this way without additional work on your part, as the content is redrawn 
instantly at the final size. At best you might get an animation where the 
content resizes into place, but more often than not, it will pop in some 
undesirable way. Generally the only way to get good animations with drawn 
content is to snapshot in some way and execute an custom animation from the old 
to the new content (snapshotting isn’t necessarily literal here – it can just 
mean creating a new label with the new content as one example).

> 
> Thanks again for any ideas.
> 
> Doug Hill
> 
> 
>> On Dec 28, 2016, at 12:50 PM, Ken Thomases  wrote:
>> 
>> On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
>>> 
>>> I can now animate my constraint changes but I notice that subviews aren't 
>>> animated. For example, I have a single view with a width constraint, and 
>>> this view has a label as a subview that expands to the size of it's parent 
>>> view via edge constraints.
>>> I can change the width constraint constant of the parent view at runtime 
>>> and it animates very well. However, the subviews jump into place 
>>> immediately then the parent view animates into place. I see the same 
>>> behavior with a button as a subview.
>> 
>> Show exactly how you're animating the constraint changes.  Are you really 
>> animating the change of the constraint or are you doing a layoutIfNeeded 
>> within an animation context?  Even if the former, are you calling any 
>> methods that force layout (layoutIfNeeded or similar)?  If so, where/when?
>> 
>> Regards,
>> Ken
>> 
> 
> 
> ___
> 
> 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

Re: Animating autolayout constraint changes for subviews

2016-12-28 Thread Steve Christensen
Sorry, I mostly copied your code and moved things around. Try -setNeedsLayout 
instead of -layoutIfNeeded.


> On Dec 28, 2016, at 9:58 PM, Doug Hill  wrote:
> 
> Hello Steve,
> 
> FWIW, I’ve tried both ways and it doesn’t seem to affect the problem I’m 
> having. However, Apple says to update constraints than do the animation block 
> with layoutIfNeeded, according to this WWDC session:
> 
> https://developer.apple.com/videos/play/wwdc2012/228/?id=228 
> 
> 
> But in general, the SDK documentation on animating autolayout constraint 
> changes is borderline non-existent. 
> 
> Doug Hill
> 
> 
>> On Dec 28, 2016, at 5:54 PM, Steve Christensen > > wrote:
>> 
>> I have always put the thing that I'm animating into the animation block:
>> 
>> - (IBAction)animateIt:(id)sender
>> {
>>  static BOOL small = NO;
>> 
>>  small = !small;
>> 
>>  CGFloat newWidth = small ? self.view.frame.size.width / 2 : 
>> self.view.frame.size.width;
>> 
>>  [UIView animateWithDuration:1 animations:
>>  ^{
>>  self.containerWidthConstraint.constant = newWidth;
>>  [self.view layoutIfNeeded];
>>  }];
>> }
>> 
>>> On Dec 28, 2016, at 4:14 PM, Doug Hill >> > wrote:
>>> 
>>> Hi Ken,
>>> 
>>> I uploaded a sample project here:
>>> 
>>> https://github.com/djfitz/TestAutolayoutAnimations 
>>> 
>>> 
>>> I tried to strip this down to what is needed to show the behavior I see.
>>> 
>>> My code to actually do the animation is this:
>>> 
>>> - (IBAction)animateIt:(id)sender
>>> {
>>> static BOOL small = NO;
>>> 
>>> if( small )
>>> {
>>> [self.view layoutIfNeeded];
>>> 
>>> self.containerWidthConstraint.constant = 
>>> self.view.frame.size.width;
>>> 
>>> [UIView animateWithDuration:1 animations:
>>> ^{
>>> [self.view layoutIfNeeded];
>>> }];
>>> }
>>> else
>>> {
>>> [self.view layoutIfNeeded];
>>> 
>>> self.containerWidthConstraint.constant = 
>>> self.view.frame.size.width / 2;
>>> 
>>> [UIView animateWithDuration:1 animations:
>>> ^{
>>> [self.view layoutIfNeeded];
>>> }];
>>> }
>>> 
>>> small = !small;
>>> }
>>> 
>>> 'container view' has one subview which is a UILabel. The label is pinned to 
>>> the superview edges via autolayout constraints. (e.g. trailing, leading, 
>>> top, bottom edges all pinned to superview edges.)
>>> 
>>> I tried a few different variations, including leaving out the first 
>>> layoutIfNeeded (which some people say should be done, others not).
>>> 
>>> The exact behavior is that the label will resize to the new size 
>>> immediately and reflow the text, then the container view will animate it's 
>>> size change. It would be nice if both the label and the container view 
>>> animate at the same time.
>>> Also, as I mentioned, a button will exhibit the same behavior, probably 
>>> because it has a UILabel inside it to show the button text.
>>> 
>>> Thanks again for any ideas.
>>> 
>>> Doug Hill
>>> 
>>> 
 On Dec 28, 2016, at 12:50 PM, Ken Thomases  wrote:
 
 On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
> 
> I can now animate my constraint changes but I notice that subviews aren't 
> animated. For example, I have a single view with a width constraint, and 
> this view has a label as a subview that expands to the size of it's 
> parent view via edge constraints.
> I can change the width constraint constant of the parent view at runtime 
> and it animates very well. However, the subviews jump into place 
> immediately then the parent view animates into place. I see the same 
> behavior with a button as a subview.
 
 Show exactly how you're animating the constraint changes.  Are you really 
 animating the change of the constraint or are you doing a layoutIfNeeded 
 within an animation context?  Even if the former, are you calling any 
 methods that force layout (layoutIfNeeded or similar)?  If so, where/when?
 
 Regards,
 Ken

___

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

Re: Animating autolayout constraint changes for subviews

2016-12-28 Thread Doug Hill
Hello Steve,

FWIW, I’ve tried both ways and it doesn’t seem to affect the problem I’m 
having. However, Apple says to update constraints than do the animation block 
with layoutIfNeeded, according to this WWDC session:

https://developer.apple.com/videos/play/wwdc2012/228/?id=228 


But in general, the SDK documentation on animating autolayout constraint 
changes is borderline non-existent. 

Doug Hill


> On Dec 28, 2016, at 5:54 PM, Steve Christensen  wrote:
> 
> I have always put the thing that I'm animating into the animation block:
> 
> - (IBAction)animateIt:(id)sender
> {
>   static BOOL small = NO;
> 
>   small = !small;
> 
>   CGFloat newWidth = small ? self.view.frame.size.width / 2 : 
> self.view.frame.size.width;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   self.containerWidthConstraint.constant = newWidth;
>   [self.view layoutIfNeeded];
>   }];
> }
> 
>> On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
>> 
>> Hi Ken,
>> 
>> I uploaded a sample project here:
>> 
>> https://github.com/djfitz/TestAutolayoutAnimations
>> 
>> I tried to strip this down to what is needed to show the behavior I see.
>> 
>> My code to actually do the animation is this:
>> 
>> - (IBAction)animateIt:(id)sender
>> {
>>  static BOOL small = NO;
>> 
>>  if( small )
>>  {
>>  [self.view layoutIfNeeded];
>> 
>>  self.containerWidthConstraint.constant = 
>> self.view.frame.size.width;
>> 
>>  [UIView animateWithDuration:1 animations:
>>  ^{
>>  [self.view layoutIfNeeded];
>>  }];
>>  }
>>  else
>>  {
>>  [self.view layoutIfNeeded];
>> 
>>  self.containerWidthConstraint.constant = 
>> self.view.frame.size.width / 2;
>> 
>>  [UIView animateWithDuration:1 animations:
>>  ^{
>>  [self.view layoutIfNeeded];
>>  }];
>>  }
>> 
>>  small = !small;
>> }
>> 
>> 'container view' has one subview which is a UILabel. The label is pinned to 
>> the superview edges via autolayout constraints. (e.g. trailing, leading, 
>> top, bottom edges all pinned to superview edges.)
>> 
>> I tried a few different variations, including leaving out the first 
>> layoutIfNeeded (which some people say should be done, others not).
>> 
>> The exact behavior is that the label will resize to the new size immediately 
>> and reflow the text, then the container view will animate it's size change. 
>> It would be nice if both the label and the container view animate at the 
>> same time.
>> Also, as I mentioned, a button will exhibit the same behavior, probably 
>> because it has a UILabel inside it to show the button text.
>> 
>> Thanks again for any ideas.
>> 
>> Doug Hill
>> 
>> 
>>> On Dec 28, 2016, at 12:50 PM, Ken Thomases  wrote:
>>> 
>>> On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
 
 I can now animate my constraint changes but I notice that subviews aren't 
 animated. For example, I have a single view with a width constraint, and 
 this view has a label as a subview that expands to the size of it's parent 
 view via edge constraints.
 I can change the width constraint constant of the parent view at runtime 
 and it animates very well. However, the subviews jump into place 
 immediately then the parent view animates into place. I see the same 
 behavior with a button as a subview.
>>> 
>>> Show exactly how you're animating the constraint changes.  Are you really 
>>> animating the change of the constraint or are you doing a layoutIfNeeded 
>>> within an animation context?  Even if the former, are you calling any 
>>> methods that force layout (layoutIfNeeded or similar)?  If so, where/when?
>>> 
>>> Regards,
>>> Ken
> 

___

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

Re: Animating autolayout constraint changes for subviews

2016-12-28 Thread Steve Christensen
I have always put the thing that I'm animating into the animation block:

- (IBAction)animateIt:(id)sender
{
static BOOL small = NO;

small = !small;

CGFloat newWidth = small ? self.view.frame.size.width / 2 : 
self.view.frame.size.width;

[UIView animateWithDuration:1 animations:
^{
self.containerWidthConstraint.constant = newWidth;
[self.view layoutIfNeeded];
}];
}

> On Dec 28, 2016, at 4:14 PM, Doug Hill  wrote:
> 
> Hi Ken,
> 
> I uploaded a sample project here:
> 
> https://github.com/djfitz/TestAutolayoutAnimations
> 
> I tried to strip this down to what is needed to show the behavior I see.
> 
> My code to actually do the animation is this:
> 
> - (IBAction)animateIt:(id)sender
> {
>   static BOOL small = NO;
> 
>   if( small )
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
>   else
>   {
>   [self.view layoutIfNeeded];
> 
>   self.containerWidthConstraint.constant = 
> self.view.frame.size.width / 2;
> 
>   [UIView animateWithDuration:1 animations:
>   ^{
>   [self.view layoutIfNeeded];
>   }];
>   }
> 
>   small = !small;
> }
> 
> 'container view' has one subview which is a UILabel. The label is pinned to 
> the superview edges via autolayout constraints. (e.g. trailing, leading, top, 
> bottom edges all pinned to superview edges.)
> 
> I tried a few different variations, including leaving out the first 
> layoutIfNeeded (which some people say should be done, others not).
> 
> The exact behavior is that the label will resize to the new size immediately 
> and reflow the text, then the container view will animate it's size change. 
> It would be nice if both the label and the container view animate at the same 
> time.
> Also, as I mentioned, a button will exhibit the same behavior, probably 
> because it has a UILabel inside it to show the button text.
> 
> Thanks again for any ideas.
> 
> Doug Hill
> 
> 
>> On Dec 28, 2016, at 12:50 PM, Ken Thomases  wrote:
>> 
>> On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
>>> 
>>> I can now animate my constraint changes but I notice that subviews aren't 
>>> animated. For example, I have a single view with a width constraint, and 
>>> this view has a label as a subview that expands to the size of it's parent 
>>> view via edge constraints.
>>> I can change the width constraint constant of the parent view at runtime 
>>> and it animates very well. However, the subviews jump into place 
>>> immediately then the parent view animates into place. I see the same 
>>> behavior with a button as a subview.
>> 
>> Show exactly how you're animating the constraint changes.  Are you really 
>> animating the change of the constraint or are you doing a layoutIfNeeded 
>> within an animation context?  Even if the former, are you calling any 
>> methods that force layout (layoutIfNeeded or similar)?  If so, where/when?
>> 
>> Regards,
>> Ken


___

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


Re: Animating autolayout constraint changes for subviews

2016-12-28 Thread Doug Hill
Hi Ken,

I uploaded a sample project here:

https://github.com/djfitz/TestAutolayoutAnimations

I tried to strip this down to what is needed to show the behavior I see.

My code to actually do the animation is this:

- (IBAction)animateIt:(id)sender
{
static BOOL small = NO;

if( small )
{
[self.view layoutIfNeeded];

self.containerWidthConstraint.constant = 
self.view.frame.size.width;

[UIView animateWithDuration:1 animations:
^{
[self.view layoutIfNeeded];
}];
}
else
{
[self.view layoutIfNeeded];

self.containerWidthConstraint.constant = 
self.view.frame.size.width / 2;

[UIView animateWithDuration:1 animations:
^{
[self.view layoutIfNeeded];
}];
}

small = !small;
}

'container view' has one subview which is a UILabel. The label is pinned to the 
superview edges via autolayout constraints. (e.g. trailing, leading, top, 
bottom edges all pinned to superview edges.)

I tried a few different variations, including leaving out the first 
layoutIfNeeded (which some people say should be done, others not).

The exact behavior is that the label will resize to the new size immediately 
and reflow the text, then the container view will animate it's size change. It 
would be nice if both the label and the container view animate at the same time.
Also, as I mentioned, a button will exhibit the same behavior, probably because 
it has a UILabel inside it to show the button text.

Thanks again for any ideas.

Doug Hill


> On Dec 28, 2016, at 12:50 PM, Ken Thomases  wrote:
> 
> On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
>> 
>> I can now animate my constraint changes but I notice that subviews aren't 
>> animated. For example, I have a single view with a width constraint, and 
>> this view has a label as a subview that expands to the size of it's parent 
>> view via edge constraints.
>> I can change the width constraint constant of the parent view at runtime and 
>> it animates very well. However, the subviews jump into place immediately 
>> then the parent view animates into place. I see the same behavior with a 
>> button as a subview.
> 
> Show exactly how you're animating the constraint changes.  Are you really 
> animating the change of the constraint or are you doing a layoutIfNeeded 
> within an animation context?  Even if the former, are you calling any methods 
> that force layout (layoutIfNeeded or similar)?  If so, where/when?
> 
> Regards,
> Ken
> 


___

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


Re: Animating autolayout constraint changes for subviews

2016-12-28 Thread Ken Thomases
On Dec 28, 2016, at 1:55 PM, Doug Hill  wrote:
> 
> I can now animate my constraint changes but I notice that subviews aren't 
> animated. For example, I have a single view with a width constraint, and this 
> view has a label as a subview that expands to the size of it's parent view 
> via edge constraints.
> I can change the width constraint constant of the parent view at runtime and 
> it animates very well. However, the subviews jump into place immediately then 
> the parent view animates into place. I see the same behavior with a button as 
> a subview.

Show exactly how you're animating the constraint changes.  Are you really 
animating the change of the constraint or are you doing a layoutIfNeeded within 
an animation context?  Even if the former, are you calling any methods that 
force layout (layoutIfNeeded or similar)?  If so, where/when?

Regards,
Ken


___

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


Animating autolayout constraint changes for subviews

2016-12-28 Thread Doug Hill
I had a previous question to the list about animating autolayout constraint 
changes at runtime. The documentation on this is a little thin and was grateful 
for the list's suggestions on the correct way to do this.

I can now animate my constraint changes but I notice that subviews aren't 
animated. For example, I have a single view with a width constraint, and this 
view has a label as a subview that expands to the size of it's parent view via 
edge constraints.
I can change the width constraint constant of the parent view at runtime and it 
animates very well. However, the subviews jump into place immediately then the 
parent view animates into place. I see the same behavior with a button as a 
subview.

Doing a Google search I see examples of other people running into this same 
problem but don't find a good solution. For example, I see people animating the 
subview themselves via a timer.

http://stackoverflow.com/questions/20097580/autolayout-animate-constraint-does-not-animate-subviews#32891810

This doesn't look like a very good solution to me since it would be almost 
impossible to match that same animation of the parent view.

Before I go too much further, I'm looking to see if there are better solutions 
out there, other other pointers to documentation about this.

Thanks.

Doug Hill
___

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