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

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; ?

Related

Positioned Off-Screen vs Hidden

I'm building an app in Xcode, using interface builder. One VC has some objects I have positioned off-screen (-600 leading to leading margin, for example). On button press, they are animated into the view.
My question is, what is the effect of having views off screen? Does it take up memory? Should I hide these views after they've animated back off to the side?
Any view that has been alloc'ed and init'ed will take up memory, off screen or not. This is more obvious in Obj-c as its when you call [UIView alloc] init] buts its still the same in swift UIView(frame: ).
The view won't draw its layers until it's been added as a subview. The view will still draw itself if it's off the parents visible rect by default. You can set the parents view to clipsToBounds = YES (swift clipsToBounds = true) and it won't draw any of its child views off screen saving some memory as the child views won't draw their layers. Not sure it's worth the effort to do that though as you only have them off screen temporarily and then animate on.
If you can you should instantiate the views right before you animate them on screen, you should 'removeFromSuperview' and set to nil, or remove them from your array, however you are storing them once the animation is done.

Update Subview in a Xib while animating bounds of superview

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.

iOS : apply affine transform to subview only

I'm have a view-parent with one background image, which scaled to whole parent view. Also in view-parent i need to display some other views. So when i apply rotation to image :
[self.backgroundView setTransform:CGAffineTransformMakeRotation((CGFloat) M_PI)];
It rotates the whole parent view - so other subviews also rotated on 180 degrees
So, how can i apply rotation only to background view without affecting other views?
Well it sounds like your backgroundView has subviews that obviously would be transformed with parent, that's by design. What you need is to make your other views siblings of your background view. Make sure you're adding subviews to backgroundView's superview and not backgroundView itself.

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.

ios alpha mask on a scrollview

I know you can mask an image in ios, but can you mask a scrollview? I'm wanting to alpha mask my scrollview so that the content on the ends appears to fade out before it gets clipped by the scrollview. Is something like this possible?
FYI I have already tried work-arounds that "fake" this effect and they don't work due to a dynamic background. I need strict alpha masking on the scrollview if at all possible.
You can fake this effect by laying over an image with alpha over the end of the scrollview. That way the fading effect stays in place, and the scrollView appears to fade out.
You can do this nicely by using layer masking:
create a mask with the appropriate alpha gradient
add the mask to the table
implement the scroll delegate, to reposition the mask to the current viewport when the table gets scrolled.
It is all explained very well here: http://www.cocoanetics.com/2011/08/adding-fading-gradients-to-uitableview/
Could you implement a footer (or last cell) that has the appropriate alpha fade to give you the effect you are looking for?

Resources