add masking to an animating uiimageview in ios - ios

I am creating a basic animation of opening and closing of doors(like in a lift, its two doors slide back and fro). I have used CABasicAnimation for translation of two doors(two imageview).
My problem is when the door(imageview) slides out, the image of the door comes out of the frame; hence I am using masking property of CALayer but I can't get the expected result.
I want the part of image of door to get masked which comes out of frame while sliding out and it should appear again while sliding in.
thanks mates.

set the property "clip subview" of the view containing this imageview as its subview in the nib file might help you

Related

tvOS: UIImageView with rounded corners without losing the focus animation

I am displaying a collection view with an UIImageView for each cell. My images are being animated on cell focus (the standard animation where the image pops out).
However, I also need to round the corners of the image by setting the imageView.layer.cornerRadius. The problem is that once I set maskToBounds = true my imageView stops popping out on focus and without that I cannot achieve the rounded corners.
I’ve checked in other SO questions and some people suggested post-process the image in runtime using Core Graphics but this is too much processing for my collectionView.
Is there any alternative to achieve this? (The iTunes movie app does it, so I suppose there must be)
Setting maskToBounds crops the image when focused because the cell extends out of its bounds to get the parallax animation.
The issue is that to generate rounded corners with that method you need to set maskToBounds to true.
So... your final goal could be achieved using a different method to generate rounded corners, via CoreGraphics for example, that does not require setting maskToBounds.
Or, what I am personally doing, to use this open source library, which allows adding parallax effect to any UIView https://github.com/PGSSoft/ParallaxView

Do I need layoutIfNeeded() or kCAGravityResize for my CALayer?

I have successfully started a session on a sublayer but the video looks like this. Do I need to add self.view.layoutIfNeeded() somewhere? If so where can I put it? I've put it in a few different areas but no go. Should I be using something called kCAGravityResize? My goal is to have the video on its own layer filling half screen and then have a tableView layer for graphics text etc filling the other half of the screen. How would I do this?
To debug this you can give the preview layer a background color. This allows you to see where the layer is, and where the video on that layer is.
I don't know your exact view hierarchy but the problem here is often that the view resizes, but the preview layer keeps the same frame.
You can subclass your view and update the preview layer's frame in layoutSublayersOfLayer:.
I seem to have got it working using viewLayer.masksToBounds. The video preview now follows the size I set for the UIImageView.

Rotating a UIImageView results in it moving back to its Storyboard starting position

This problem occurs when I perform transformations on my images. I can reposition a UIImageView by resetting its center using CGPointMake, but when I go to rotate it with a line like,
image1.transform = CGAffineTransformRotate([image1 transform],angle);
the UIImage moves back to its original position (the place where I put it in my StoryBoard editor).
This person has my exact problem in his post:
Rotating uiimageview moves image back to original storyboard position
Going to the File inspector in interface builder, and unticking "Use Auto Layout" seems to solve the problem, however constraints are turned off when one does this. It is a good temporary solution, however. The first comment under my question also has some great info on the matter.

Making an element an element display on top of the UIView border

I am trying to place a UIButton inbetween my popup view and the parent view.
I cant successfully do that by doing that [self.view addSubview:new];. My problem there is the border UIView can be seen across the UIButton .
I've tried [self.view.superview addSubview:new]; thinking that that would make it go away but it doesnt it still shows there.
I need to find a way to successfully place that button on top of everything (UIView border in this case).
I know I could do that if I insert the button from the parentView, but I want to handle all my subViews buttons within each subView, otherwise it everything will become messy very quickly.
Is there a way to do what I am trying to achieve?
According to Apple's CALayer documentation, borders always appear above subviews because they're drawn on another layer. The best solution is to create a background view to fake the border.
So instead, your popup view would have an orange background. It'd have another, slightly smaller subview directly over it with a white background, and then your button.
See this post for the implementation.

Custom UIbutton down part does not recognize touchup inside

I created a custom UIbutton and placed it onto a view which shows certain information about a package.I want the whole area to be touchable as button that was my starting point.THe problem is that only the upper half of the custom button is touchable and the down part is ignored.I set the background color to a solid one and the frame seems to be ok.
UPDATE: If i add the same custom button to superview it seems to be ok but the coordinates are not right in this case.I need to convert the coordinates of the subview to super view.
After struggling so many hours i figured out that my outer frame was smaller than it was supposed to be.

Resources