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: Custom NSCollectionViewLayout isn't causing scrollbars to appear

2016-12-28 Thread Steve Mills
On Dec 28, 2016, at 20:26:52, Rob Petrovec  wrote:
> 
> You need to specify the scroll direction via -scrollDirection and return an 
> NSSize large enough for a scroll bar from -collectionViewContentSize.  Hope 
> that helps.

-scrollDirection is a method only available for NSCollectionViewFlowLayout. I 
said I'm using a custom layout class, which is a subclass of 
NSCollectionViewLayout. I also don't believe the size returned from 
-collectionViewContentSize should include space for scrollbars. The docs say 
"size of the contents". Scrollbars are not content.

--
Steve Mills
Drummer, Mac geek


___

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: Connecting NSTextStorage to a string

2016-12-28 Thread Kyle Sluder
> On Fri, Dec 23, 2016, at 09:16 PM, Daryle Walker wrote:
> The text controls on macOS use a NSTextStorage object to retain their
> text. That object is a extension of an attributed string. Let's say you
> use a NSString (or similar) in your document model. How should I get
> changes on one string to get mirrored on the other?

It depends on what you’re trying to do. The Cocoa text system is set up for two 
modes: editing rich text, and editing non-rich text.

In the rich-text case, the NSTextStorage object is intended to *be* the model 
object. It’s a long-lived object with its own optimized mutation scheme 
(-beginEditing/-endEditing and the mutators it inherits from 
NSMutableAttributedString), which is married to one particular NSTextView 
instance in the window. This of course means it’s not a great fit for 
frameworks like Core Data or Cocoa Bindings which expect model object 
properties to be simple value types. You can bridge this gap with various 
techniques, such as registering an object as the NSTextStorage’s delegate that 
posts your own notifications or triggers change notifications for a synthesized 
Core Data property.

The non-rich-text mode is more straightforward. In this mode, the NSTextStorage 
is permanently married to the window’s field editor, and as focus moves around 
the window its contents are batch-replaced with the underlying control’s 
stringValue as focus moves around the window. The controller is expected to 
listen to NSControl text editing notifications (possibly by acting as the 
control’s delegate) to know when to push values to the model. It is expected to 
use some other means, such as KVO, to push values from the model to the 
control. Cocoa Bindings intends to do this two-way marshaling on your behalf.

--Kyle Sluder

> 
> I think there are begin/end-editing flag methods on text controls, but
> how would I go the other way?
> 
> Sent from my iPhone


___

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: Custom NSCollectionViewLayout isn't causing scrollbars to appear

2016-12-28 Thread Rob Petrovec
You need to specify the scroll direction via -scrollDirection and return an 
NSSize large enough for a scroll bar from -collectionViewContentSize.  Hope 
that helps.

—Rob


> On Dec 23, 2016, at 11:23 AM, Steve Mills  wrote:
> 
> I'm using a custom layout subclass because I want a specific number of 
> columns at a specific size, which should cause the scroll view's horizontal 
> scrollbar to appear, but it's not. What do I have to do to make it appear? 
> The checkbox for both scrollbars is turned on in IB.
> 
> --
> Steve Mills
> Drummer, Mac geek
> 
> 
> ___
> 
> 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/petrock%40mac.com
> 
> This email sent to petr...@mac.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

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