Re: How to detect rotation in progress in viewDidLayoutSubview
Re: How to detect rotation in progress in viewDidLayoutSubview
- Subject: Re: How to detect rotation in progress in viewDidLayoutSubview
- From: David Duncan <email@hidden>
- Date: Mon, 28 Nov 2016 10:50:53 -0500
> On Nov 27, 2016, at 7:25 AM, Andreas Falkenhahn <email@hidden> wrote:
>
> On 27.11.2016 at 00:04 David Duncan wrote:
>
>> What are you trying to accomplish?
>
> I want to keep my UIView centered on the screen so I need to
> change its position when the device rotates. I'm currently
> moving the UIView to the new position using
>
> [myView setFrame:...];
>
> in viewDidLayoutSubviews().
I think you can do everything you need to do in layoutSubviews (fundamentally it doesn’t matter if the device rotates or not, you just want to keep the view centered in its superview).
>
>> For most developers just looking at the aspect ratio in
>> viewDidLayoutSubviews is sufficient.
>
> Right, this would probably be a nicer way than using a flag.
>
>> If you only want to do
>> something for rotating, doing it as an alongside animation in
>> viewWillTransitionToSize is usually what you want.
>
> Do you mean that I should move the UIView in my "animateAlongsideTransition"
> block instead of viewDidLayoutSubviews()? This seems to work as
> well but I don't really know anything about those animation
> handlers so I felt more comfortable doing this in viewDidLayoutSubviews().
In general you should do as much as possible in layoutSubviews type methods. However sometimes you really do want to do something temporary specifically due to a transition between sizes, orientations, or size classes, and hence why we provide the “willTransitionTo” methods. If it isn’t a temporary change, then you don’t want the transition methods, as they are not always called at points when layoutSubviews will be.
>
>> Also from your last thread, if you are trying to fix up a
>> transform, it may be easier to use contentMode instead of transform
>> for this case. AspectFit vs AspectFill will do the common letterbox
>> vs clip without you needing to do anything further.
>
> Yes, I'm actually using contentMode now. If this is set to
> UIViewContentModeScaleToFill, I can just change the bounds
> of the UIView and I'll get GPU-accelerated scaling for free
>
> --
> Best regards,
> Andreas Falkenhahn mailto:email@hidden
>
--
David Duncan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden