Re: How to constrain a UISlider in a UIToolbar?

2014-07-31 Thread David Duncan

 On Jul 30, 2014, at 9:00 PM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 
 On 31 Jul 2014, at 00:18, David Duncan david.dun...@apple.com wrote:
 
 That's the purpose of setting the auto-resizing mask to FlexibleWidth. At 
 least for title views, that causes UINavigationBar to send -sizeThatFits: 
 to the view.
 
 For UINavigationBar you shouldn’t need to even set flexible width, just 
 implement -sizeThatFits:. Unfortunately UIToolbar does not call 
 -sizeThatFits: for the views of bar button items.
 
 Gerriet, you can try setting the frame of the slider then calling 
 -setNeedsLayout/-layoutIfNeeded on the toolbar to update the layout. If you 
 do this within the standard layout callbacks it should go along with any 
 animation that is already going.
 
 Following your suggestion I changed my code to:
 
 override func viewWillLayoutSubviews()//  manage slider in 
 bottomToolBar
 {
   //  current width of toolbar is all wrong. Need to do:
   bottomToolBar.setNeedsLayout()
   bottomToolBar.layoutIfNeeded()
   

Assuming that you're in a typical case (the toolbar is the same width as your 
view) you can just use self.view.bounds.width instead of 
bottomToolBar.frame.size.width here. This is likely to be more robust (given 
that calling setNeedsLayout/layoutIfNeeded on the toolbar as you do above 
really should not change the toolbar’s size…).

   //  now the toolbar width seems to be right 
   let b = bottomToolBar.frame.size.width
   speedSlider.frame.size.width = b - 40
   
   bottomToolBar.setNeedsLayout()
   bottomToolBar.layoutIfNeeded()
 }
 
 Works perfectly now. Thanks a lot!

Glad it worked!

 
 
 Kind regards,
 
 Gerriet.
 
 

--
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: How to constrain a UISlider in a UIToolbar?

2014-07-31 Thread Kyle Sluder
On Jul 31, 2014, at 10:05 AM, David Duncan david.dun...@apple.com wrote:
 
 
 On Jul 30, 2014, at 9:00 PM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 
 On 31 Jul 2014, at 00:18, David Duncan david.dun...@apple.com wrote:
 
 That's the purpose of setting the auto-resizing mask to FlexibleWidth. At 
 least for title views, that causes UINavigationBar to send -sizeThatFits: 
 to the view.
 
 For UINavigationBar you shouldn’t need to even set flexible width, just 
 implement -sizeThatFits:. Unfortunately UIToolbar does not call 
 -sizeThatFits: for the views of bar button items.
 
 Gerriet, you can try setting the frame of the slider then calling 
 -setNeedsLayout/-layoutIfNeeded on the toolbar to update the layout. If you 
 do this within the standard layout callbacks it should go along with any 
 animation that is already going.
 
 Following your suggestion I changed my code to:
 
 override func viewWillLayoutSubviews()//manage slider in 
 bottomToolBar
 {
//current width of toolbar is all wrong. Need to do:
bottomToolBar.setNeedsLayout()
bottomToolBar.layoutIfNeeded()
 
 Assuming that you're in a typical case (the toolbar is the same width as your 
 view) you can just use self.view.bounds.width instead of 
 bottomToolBar.frame.size.width here. This is likely to be more robust

Really? This goes against my instinct… the desired result is that the slider 
take up a certain percentage of its superview. Therefore the computation should 
encode this relationship.

 (given that calling setNeedsLayout/layoutIfNeeded on the toolbar as you do 
 above really should not change the toolbar’s size…).

This actually gets at a question I’ve had for a while—does -layoutIfNeeded 
resize the receiver, or only its subviews? I’m not sure the docs are explicit 
about this.

--Kyle Sluder

___

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: How to constrain a UISlider in a UIToolbar?

2014-07-31 Thread David Duncan

 On Jul 31, 2014, at 10:24 AM, Kyle Sluder k...@ksluder.com wrote:
 
 On Jul 31, 2014, at 10:05 AM, David Duncan david.dun...@apple.com wrote:
 
 
 On Jul 30, 2014, at 9:00 PM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 
 On 31 Jul 2014, at 00:18, David Duncan david.dun...@apple.com wrote:
 
 That's the purpose of setting the auto-resizing mask to FlexibleWidth. At 
 least for title views, that causes UINavigationBar to send -sizeThatFits: 
 to the view.
 
 For UINavigationBar you shouldn’t need to even set flexible width, just 
 implement -sizeThatFits:. Unfortunately UIToolbar does not call 
 -sizeThatFits: for the views of bar button items.
 
 Gerriet, you can try setting the frame of the slider then calling 
 -setNeedsLayout/-layoutIfNeeded on the toolbar to update the layout. If 
 you do this within the standard layout callbacks it should go along with 
 any animation that is already going.
 
 Following your suggestion I changed my code to:
 
 override func viewWillLayoutSubviews()//manage slider in 
 bottomToolBar
 {
   //current width of toolbar is all wrong. Need to do:
   bottomToolBar.setNeedsLayout()
   bottomToolBar.layoutIfNeeded()
 
 Assuming that you're in a typical case (the toolbar is the same width as 
 your view) you can just use self.view.bounds.width instead of 
 bottomToolBar.frame.size.width here. This is likely to be more robust
 
 Really? This goes against my instinct… the desired result is that the slider 
 take up a certain percentage of its superview. Therefore the computation 
 should encode this relationship.

I say this mostly because of my answer to your next question...

 
 (given that calling setNeedsLayout/layoutIfNeeded on the toolbar as you do 
 above really should not change the toolbar’s size…).
 
 This actually gets at a question I’ve had for a while—does -layoutIfNeeded 
 resize the receiver, or only its subviews? I’m not sure the docs are explicit 
 about this.

… which is that [view layoutIfNeeded] should not resize ‘view’ in the general 
case. What is likely happening here is that the layout is climbing up to the 
superview and then descending back down, but thats not something to be counted 
on (if the superview isn’t marked as dirty, this may not happen).

So I am also not terribly satisfied with using view.bounds as a proxy for 
toolbar.frame, but should the code paths that make this work change 
sufficiently in the future that [view layoutIfNeeded] does not resize the 
toolbar, this code would be broken (in so far as the slider would not be the 
right size) but if the overall layout guaranteed the toolbar would be the full 
width of the view then the proxying is at least justifiable.

I would hope that we can make this better in the future overall, as things like 
this should really be very automatic.

 
 --Kyle Sluder

--
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: How to constrain a UISlider in a UIToolbar?

2014-07-30 Thread Gerriet M. Denkmann

On 30 Jul 2014, at 11:27, Kyle Sluder k...@ksluder.com wrote:

 On Jul 29, 2014, at 9:11 PM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 
 But nobody ever cares to call sizeThatFits or systemLayoutSizeFittingSize.
 
 Overriding requiresConstraintBasedLayout and returning either YES or NO 
 makes no difference.
 
 Anything else I forgot to override?
 
 Hmm, I'm pretty sure that’s all we override. Have you tried dropping our 
 document title view into the toolbar and seeing what happens?

No, I did not. It depends on OFBindingPoint et al., which might depend on other 
things, etc., etc.
But I studied it diligently.

The problem (I guess) is that UIToolbar does not use LayoutConstraints at all. 
And it probably simply does not expect any of it's UIBarButtonItems to change 
their size.

Anyway, this:
override func viewDidLoad() 
{
let b = bottomToolBar.frame.size.width
speedSlider.frame.size.width = b - 8
super.viewDidLoad()
}

kind of works.
In Landscape the slider could be bigger though.
Maybe I could register for UIDeviceOrientationDidChangeNotifications and then 
do the same thing again.


Kind regards,

Gerriet.


___

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: How to constrain a UISlider in a UIToolbar?

2014-07-30 Thread Roland King

 On 30 Jul 2014, at 2:30 pm, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 
 
 
 Hmm, I'm pretty sure that’s all we override. Have you tried dropping our 
 document title view into the toolbar and seeing what happens?
 
 No, I did not. It depends on OFBindingPoint et al., which might depend on 
 other things, etc., etc.
 But I studied it diligently.
 
 The problem (I guess) is that UIToolbar does not use LayoutConstraints at 
 all. And it probably simply does not expect any of it's UIBarButtonItems to 
 change their size.
 

I think it’s because even though UIToolbar is a UIView subclass, 
UIButtonBarItem, which goes on it, isn’t. I never really understood why that 
was, it has that ‘NSCell’ code smell about it, feels like something done for 
efficient button bars in iOS 2.0 we’ll all suffer for forever. I assume that 
you kept the width of the button bar item which contains your custom view at 
the default of 0.0 right? It claims in that instance that the item sets the 
width to fit but I suspect that really only works if the content is a fixed 
icon and not a UIView. 

Can you pin a view over the top of the toolbar using constraints (they are both 
sibling UIViews after all) then pin your slider in there? 
___

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: How to constrain a UISlider in a UIToolbar?

2014-07-30 Thread Kyle Sluder
 On Jul 30, 2014, at 7:44 AM, Roland King r...@rols.org wrote:
 
 
 On 30 Jul 2014, at 2:30 pm, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:
 
 
 
 Hmm, I'm pretty sure that’s all we override. Have you tried dropping our 
 document title view into the toolbar and seeing what happens?
 
 No, I did not. It depends on OFBindingPoint et al., which might depend on 
 other things, etc., etc.
 But I studied it diligently.
 
 The problem (I guess) is that UIToolbar does not use LayoutConstraints at 
 all. And it probably simply does not expect any of it's UIBarButtonItems to 
 change their size.
 
 I think it’s because even though UIToolbar is a UIView subclass, 
 UIButtonBarItem, which goes on it, isn’t.

Well, bar button items can have custom views, and sometimes non-view bar button 
items are encased in a view. So it’s definitely designed to work with views, 
and could be made to work with constraints.

 I never really understood why that was, it has that ‘NSCell’ code smell about 
 it, feels like something done for efficient button bars in iOS 2.0 we’ll all 
 suffer for forever.

The good thing about an abstracted API is that Apple could switch to 
one-view-per-bar-button-item tomorrow and none of us would know unless we 
looked.

 I assume that you kept the width of the button bar item which contains your 
 custom view at the default of 0.0 right? It claims in that instance that the 
 item sets the width to fit but I suspect that really only works if the 
 content is a fixed icon and not a UIView. 

That's the purpose of setting the auto-resizing mask to FlexibleWidth. At least 
for title views, that causes UINavigationBar to send -sizeThatFits: to the view.

 
 Can you pin a view over the top of the toolbar using constraints (they are 
 both sibling UIViews after all) then pin your slider in there?

This might work visually, but make sure to get accessibility right.

--Kyle Sluder
___

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: How to constrain a UISlider in a UIToolbar?

2014-07-30 Thread David Duncan

 On Jul 30, 2014, at 8:49 AM, Kyle Sluder k...@ksluder.com wrote:
 
 On Jul 30, 2014, at 7:44 AM, Roland King r...@rols.org wrote:
 
 
 On 30 Jul 2014, at 2:30 pm, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 
 
 Hmm, I'm pretty sure that’s all we override. Have you tried dropping our 
 document title view into the toolbar and seeing what happens?
 
 No, I did not. It depends on OFBindingPoint et al., which might depend on 
 other things, etc., etc.
 But I studied it diligently.
 
 The problem (I guess) is that UIToolbar does not use LayoutConstraints at 
 all. And it probably simply does not expect any of it's UIBarButtonItems to 
 change their size.
 
 I think it’s because even though UIToolbar is a UIView subclass, 
 UIButtonBarItem, which goes on it, isn’t.
 
 Well, bar button items can have custom views, and sometimes non-view bar 
 button items are encased in a view. So it’s definitely designed to work with 
 views, and could be made to work with constraints.

Just wanted to chime in to ask anyone interested in using constraints with bars 
(NavigationBar  Toolbar primarily) to please file bugs with the kinds of 
things you want to do.

 
 I never really understood why that was, it has that ‘NSCell’ code smell 
 about it, feels like something done for efficient button bars in iOS 2.0 
 we’ll all suffer for forever.
 
 The good thing about an abstracted API is that Apple could switch to 
 one-view-per-bar-button-item tomorrow and none of us would know unless we 
 looked.

Most people haven’t ;-).

 
 I assume that you kept the width of the button bar item which contains your 
 custom view at the default of 0.0 right? It claims in that instance that the 
 item sets the width to fit but I suspect that really only works if the 
 content is a fixed icon and not a UIView. 
 
 That's the purpose of setting the auto-resizing mask to FlexibleWidth. At 
 least for title views, that causes UINavigationBar to send -sizeThatFits: to 
 the view.

For UINavigationBar you shouldn’t need to even set flexible width, just 
implement -sizeThatFits:. Unfortunately UIToolbar does not call -sizeThatFits: 
for the views of bar button items.

Gerriet, you can try setting the frame of the slider then calling 
-setNeedsLayout/-layoutIfNeeded on the toolbar to update the layout. If you do 
this within the standard layout callbacks it should go along with any animation 
that is already going.

 
 
 Can you pin a view over the top of the toolbar using constraints (they are 
 both sibling UIViews after all) then pin your slider in there?
 
 This might work visually, but make sure to get accessibility right.
 
 --Kyle Sluder
 ___
 
 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: How to constrain a UISlider in a UIToolbar?

2014-07-30 Thread Gerriet M. Denkmann

On 31 Jul 2014, at 00:18, David Duncan david.dun...@apple.com wrote:

 That's the purpose of setting the auto-resizing mask to FlexibleWidth. At 
 least for title views, that causes UINavigationBar to send -sizeThatFits: to 
 the view.
 
 For UINavigationBar you shouldn’t need to even set flexible width, just 
 implement -sizeThatFits:. Unfortunately UIToolbar does not call 
 -sizeThatFits: for the views of bar button items.
 
 Gerriet, you can try setting the frame of the slider then calling 
 -setNeedsLayout/-layoutIfNeeded on the toolbar to update the layout. If you 
 do this within the standard layout callbacks it should go along with any 
 animation that is already going.

Following your suggestion I changed my code to:

override func viewWillLayoutSubviews()  //  manage slider in bottomToolBar
{
//  current width of toolbar is all wrong. Need to do:
bottomToolBar.setNeedsLayout()
bottomToolBar.layoutIfNeeded()

//  now the toolbar width seems to be right 
let b = bottomToolBar.frame.size.width
speedSlider.frame.size.width = b - 40

bottomToolBar.setNeedsLayout()
bottomToolBar.layoutIfNeeded()
}

Works perfectly now. Thanks a lot!


Kind regards,

Gerriet.



___

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: How to constrain a UISlider in a UIToolbar?

2014-07-29 Thread Kyle Sluder
 On Jul 29, 2014, at 2:34 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 I have a UIToolbar which contains a UISlider, flanked by two flexible spaces.
 I would like to have this slider to be as big as possible.
 Setting it's width does not make sense, as the UIToolbar width changes, 
 depending on device and orientation.
 
 And setting constraints on the slider seems to be impossible (Xcode 6 beta 4).
 
 Any ideas?

You need to put your slider inside of a subclass of UIView whose implementation 
of -sizeThatFits: returns an appropriate value.

In our document-based iPad apps, we use this technique to put a “Sync” button 
adjacent to the document title.

Here’s the source code to our implementation: 
https://github.com/omnigroup/OmniGroup/blob/master/Frameworks/OmniUI/iPad-Document/OUIDocumentTitleView.m

--Kyle Sluder

___

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: How to constrain a UISlider in a UIToolbar?

2014-07-29 Thread Gerriet M. Denkmann

On 29 Jul 2014, at 22:14, Kyle Sluder k...@ksluder.com wrote:

 On Jul 29, 2014, at 2:34 AM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 I have a UIToolbar which contains a UISlider, flanked by two flexible spaces.
 I would like to have this slider to be as big as possible.
 Setting it's width does not make sense, as the UIToolbar width changes, 
 depending on device and orientation.
 
 And setting constraints on the slider seems to be impossible (Xcode 6 beta 
 4).
 
 Any ideas?
 
 You need to put your slider inside of a subclass of UIView whose 
 implementation of -sizeThatFits: returns an appropriate value.

This sounds like an excellent idea.
Now my bottom UIToolbar looks like:
Flexible Space, ViewWithSlider, Flexible Space

ViewWithSlider is:

import UIKit

class ViewWithSlider: UIView
{
init( coder: NSCoder )
{
let functionName = -[ViewWithSlider initWithCoder] 
println(functionName + will call super)
super.init(coder: coder)
}

override func updateConstraints()   
{
let functionName = -[ViewWithSlider updateConstraints] 
println(functionName + will call super)
super.updateConstraints()
}

override func sizeThatFits( size: CGSize ) - CGSize//  never 
called 
{
let functionName = -[ViewWithSlider sizeThatFits \(size)] 
let superSize = super.sizeThatFits( size )
println(functionName + super fits \(superSize))
return superSize
}

override func systemLayoutSizeFittingSize( size: CGSize ) - CGSize 
//  never called 
{
let functionName = -[ViewWithSlider 
systemLayoutSizeFittingSize \(size)] 
let superSize = super.systemLayoutSizeFittingSize( size )
println(functionName + super fits \(superSize))
return superSize
}
}

and it prints:
-[ViewWithSlider initWithCoder] will call super
-[ViewWithSlider updateConstraints] will call super

But nobody ever cares to call sizeThatFits or systemLayoutSizeFittingSize.

Overriding requiresConstraintBasedLayout and returning either YES or NO makes 
no difference.

Anything else I forgot to override?


Kind regards,

Gerriet.


___

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: How to constrain a UISlider in a UIToolbar?

2014-07-29 Thread Kyle Sluder
 On Jul 29, 2014, at 9:11 PM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 
 
 But nobody ever cares to call sizeThatFits or systemLayoutSizeFittingSize.
 
 Overriding requiresConstraintBasedLayout and returning either YES or NO makes 
 no difference.
 
 Anything else I forgot to override?

Hmm, I'm pretty sure that’s all we override. Have you tried dropping our 
document title view into the toolbar and seeing what happens?

--Kyle Sluder

___

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