Update Subview in a Xib while animating bounds of superview - ios

I am working on animating in a modal-like window, which has been built in a Xib using auto-layout constraints. I am attempting to make it appear to grow from a UITableViewCell on tap. I've noticed that only the superview will animate it's bounds (width and height) using CAKeyframeAnimation(keyPath: "bounds.size"), while none of it's subviews change at all.
I do not want to use CATransform3D as that ends up distorting images and text in the subview.I've also tried layoutIfNeeded() before and after the animation, but it doesn't seem to make a difference on animating the subviews.I also tried snapshotting, but it would not work because the view is not rendered on the screen until the animation begins.
Any thoughts on making this work would be greatly appreciated.

Related

UIView CGAffineTransform scale issue (autolayout issue?)

I am trying to apply a simple CGAffineTransform to an imageView by scaling to 0, but for some reason the frame of the imageView is getting screwed up just before the animation starts. It appears as though autolayout is applying to the shrunken view. I don't want that at all. I want the view to remain "relatively" where it was and just visually shrink to its center, but because the view is tied to the top and right of its containing view, it is being moved.
What I want is for it to shrink into its center and disappear, but just before it starts, the frame of the imageView is jumping to the top-right of its container (it seems as though iOS is calculating its size after the animation and using that to reposition it before the animation starts). After it jumps there, the animation works properly with respect to itself, with the view shrinking relative to its center, but I want to avoid it moving in the first place.
This is all taking place inside a UITableViewCell that is managed by autolayout, so I'm guessing this has something to do with autolayout and <understatement> would not be the first time autolayout has gotten in my way </understatement>.
Is there any way to prevent autolayout from affecting the transform?

How can I maintain relative scrolling position within a UIScrollView during a UISnapBehavior animation?

I am using a UIDynamicAnimator's UISnapBehavior to animate these circles between two states:
http://cl.ly/image/1G3p1B2x2v14/Image%202013.09.24%2011%3A35%3A43%20AM.png
That works great. However, I then put this inside a UIScrollView. When I scroll before the UISnapBehavior animation has "settled" (there seems to be a delay after it looks like it finishes and when it actually finishes), the circles lose their relative positioning to the scroll container:
http://cl.ly/image/1E0I3l460J1V/Image%202013.09.24%2011%3A32%3A10%20AM.png
When I scroll after waiting a few seconds after the animation has "settled", the circles do not lose their relative positioning
I'm assuming this is because UISnapBehavior animates things with fixed positions, and then reverts back to relative positioning after it finishes, but I'm not sure if that's true.
I was setting the UIDynamicAnimator on a UIView containing the UIScrollView. Setting the UIDynamicAnimator initWithTarget to the UIScrollView seems to have fixed it.
Try putting your circles within a UIView that's a subview of a UIScrollView instead of in the scroll view itself. I've seen it do some weird things before.

UIView animation clips view bounds. Any way to prevent clipping?

I have a UIView animation that does a vertical flip animation transition from one view to another. The problem is that the view has some overflowed content (achieved by setting clipsToBounds to NO on the view), and during the animation, the overflowed content gets clipped.
Is there any way to prevent CoreAnimation from clipping the views?
Screenshots
Normal view (notice the paperclip and overhanging rope along the top edge of the map):
Animation in flight: (paperclip and rope are clipped)
I'd recommend placing all the views which rotate inside of a transparent view (kind of placeholder for "map" and "clip"), and applying animation to it rather than to your map view.
Try to set placeholder view's size the way its subviews won't overflow, so you can not worry about hacking clipsToBounds.
have you tried: myView.layer.masksToBounds = NO; ?

Resize content of UIScrollView when zooming

I know there is many topics for this subject but I didn't found a good solution for my problem.
I have a UIScrollView with an image and other components added as subviews.
I just want to know the good way to resize the components into in real time when I zoom.
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
// Resizing image and other components
}
EDIT : I would like the impression that the components inside the scroll view keep the same size when I zoom. I don't want to they become bigger or smaller during zooming.
EDIT : Here is the hierarchy of my UIViewController
View
ScrollView
Main view
Image view
Drawing view (UIView with components like UILabel, other UIViews, etc...)
Thanks a lot !
I would leave the scale of UIScrollView as it is and reach the goal with the help of subview (adjusting its size, not scrollView's), where I would place all the subviews and the images you work with.
So it would be something like:
yourView.transform = CATransform3DMakeScale(newScale, newScale, 1.0);
where yourView is the main (only) subview of scrollView. Then I would recalculate the size of the yourView with new scale and set it to scrollView's contentSize parameter so that you could actually scroll the enlarged content, not only see it truncated.
The only thing is that in this case you should use the callback other than scrollViewDidZoom: I guess.
P.S. Changing UIView's transform parameter you don't need to bother about subviews' scale: CoreAnimation does everything for you.

UIScrollView unwanted scrolling after addSubview or changing frame

I have a UIScrollView filled with subviews, all is well when creating it and initially filling it.
But when I add a new subview that is positionned outside of the visible screen portion, or when I just resize an existing subview that is also outside of the visible screen portion, there is a subsequent 0.3s-long scroll animation (I can see it happening from my delegate) that seems to match the newly added/resized element.
Attempts:
pagingEnabled is always NO.
Setting scrollEnabled to NO during subview manipulations doesn't help.
Doing a setContentOffset:animated:NO after subview manipulations doesn't prevent the animation.
One single giant subview with all my subviews in it doesn't help.
My current workaround is to initially set the frame to fit inside the visible screen portion, or doing resizing work inside another superview, but it feels dirty, and won't handle all situations...
Is there a way to prevent this automatic scrolling animation when programmatically manipulating subviews?
Xcode 4.3, iOS SDK for 5.1.
I too discovered this problem and found this solution http://www.iphonedevsdk.com/forum/iphone-sdk-development/94288-disabling-uiscrollview-autoscroll.html
It involves subclassing the UIScrollView and entering no code in the following method.
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated {
}
Like the guy says on the link I've found it works and no problems so far. Hope it works for you.
I had this problem because I set the content size of the scroll view prior to adding the subview.
As soon as I change the code so that the content size of the scroll view was set after adding the subview the problem went away.

Resources