On Nov 12, 2015, at 6:13 PM, Dragan Milić <[email protected]> wrote:
> 
> What I want to achieve currently is a simple media player view (and instance 
> of AVPlayerView) within some superview hierarchy. I want this playerView to 
> behave as follows:
> 
> * it must be horizontally centred inside its superview
> * it must be vertically centred inside its superview
> * it must maintain its aspect ratio (which is determined by the natural size 
> of the video track being played)
> * as the superview shrinks, the playerView must shrink also
> * as the superview expands, the playerView must expand only until it reaches 
> the natural size of the video track being played (to avoid blurriness it 
> people try to go beyond that size)
> 
> This above is quite hard to accomplish in all possible scenarios if a view 
> doesn’t define its intrinsic content size (like AVPlayerView doesn’t), but if 
> it does the things get pretty simple. So, I subclassed AVPlayerView to define 
> its intrinsic content size (as the size of the video track being played) and 
> the constraints are set as follows:
> 
> * playerView.center.X = superview.center.X
> * playerView.center.Y = superview.center.Y
> * playerView.leading  >= superview.leading
> * playerView.top >= superview.top
> * playerView.width : playerView.height = intrinsicContentSize.width : 
> intrinsic.ContentSize.height

> I tried to set the content compression priority very low (=1), but no 
> difference in behaviour. I also played with different level on holding 
> proprieties of splitViews’ subview, that didn’t help either. I suppose some 
> NSSplitView behaviour is involved here, but I don’t know which one and I’m 
> not able to figure it out. (As a side note, NSSplitView was quite a pain with 
> springs & struts, it seems to continue being so with autolayout).
> 
> Any help in demystifying this behaviour is very appreciated.

Try, as an experiment, leaving out the aspect ratio constraint.  If that 
changes the split view behavior, try putting it back but at a priority lower 
than the split view holding priorities.

I suspect the problem is that, as the video player is forced to shrink, it 
can't maintain its _exact_ aspect ratio (in part because the auto layout system 
tries to maintain whole-pixel sizes).  Since the aspect ratio constraint is at 
a higher priority than the split view holding priorities, auto layout prefers 
to break those before breaking it.  Once it does decide to break the aspect 
ratio constraint, it still tries to get as close as possible, which is why the 
player does maintain its aspect ratio as far as the eye can tell.

Regards,
Ken


_______________________________________________

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