简体   繁体   中英

Custom ViewController Transitions: Get ToViewController's Subview's Frame

Here's an illustration of my question:

插图

I have StarImageView s in ViewControllers A & B that displays the same image but have different frames from each other in its ViewController.

When StarImageView in ViewController A is tapped, the app pushes a new view controller into the navigation controller stack and at the same time, animates to its final frame in ViewController B.

This behaviour is just like the transition in the iPhone Photos app.


How I'm doing it now

I initialise a temp UIImageView in the animator object with the initial StarImageView's frame and image in ViewController A, and animate it to a final frame by hard-coding the rect CGRectMake(0, 60+44, containerView.bounds.size.width, containerView.bounds.size.width) (frame of StarImageView in ViewController B), and removing the temp UIImageView from superview in the animation completion block.


How I wish to do it instead

The project is created in storyboard with autolayout enabled. What I wish to do is to get the frame of StarImageView in ViewController B during the transition rather than hard-coding it like above. Due to the ViewContorller lifecycle, I am unable to reference any subviews in ViewController B in the animator object as they haven't been initialised yet.

Are there any other solutions or best practices for such situations? Thanks in advance!

PS I've seen this , this , and this but no luck in an answer.

[toViewController.view layoutIfNeeded];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM