CATiledLayer is being rendered underneath a UIView - ios

I'm making a PDF reader that looks like a real book.
I have a UIImageView inside a scrollview as the book's background (imagine an open book with empty pages). The UIImageView's layer has 2 sublayers each positioned over each page, CATiledLayers that render PDF content.
I have 2 UIViews whose layer uses an image as its contents. When I hit a button to turn the page, I take the CATiledLayer attached to the background and remove him but then add him to the UIView's layer as a sublayer. This UIView's layer animates a page turning, and with it animates that PDF page. I create a new PDF page and put it where the old one used to be.
So now there is a PDF page as a sublayer on the background UIImageView, and a UIView overtop of that with a PDF page as a sublayer. For some reason the PDF on the page underneath is visible during the animation. It should not be visible because the turning page should be obstructing it. Question is, why is that happening?

I just had to change the zPosition property of the UIView's layers to a really high number like 10000. I had it set to 0.1 initially but that wasn't enough. Then the compositing worked again.

Related

Outbounds Image Pieces in PageCurl Transition on UIPageViewController

I have an application in which I have implemented the system transitions between views UIPageViewController offers. The problem I have is that in each view images placed indicating the Frame where they have to be affixed. If this frame outside the screen, when I make the transition to pass page, the pieces of the images protruding frames page are shown. I know the best way for do this is edit the image erasing this piece, but the problem is that this images with I have the problem, are dynamically set in place for each size of screen
The best way to this is setting view.clipsToBounds = true.

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.

Want a UIVisualEffectView affected by content above as well as below it?

I have a UIVisualEffectView with a UIBlurEffect effect as a pinned UICollectionViewCell in a UICollectionView.
The blur is masked with an icon so that the icon appears in a subtle shimmery way, responding to whatever it is drawn on top of.
The effect is on top of the collection's background. As it stays pinned and the varying background scrolls underneath, it gently changes to reflect the background and looks very nice.
However, except for the collections's scrolling background, most content is drawn in front of the blur effect. This is necessary because that other content is more important and shouldn't be obscured.
Even though it is behind the more important content, I'd like the effect view to reflect the content that is scrolling in front of it. Any suggestions for how this might be made to work?
Ideas:
Could I grab a chunk from the previously drawn frame and draw this under the effect view? How would I do that?
Could I render the whole collection view, apply the blur, and then render everything that should be on top of the blur a second time? How can I make that efficient?!
Thanks.
I went with a slightly refined version of the second option.
I added some duplicate cells to the collection view that are rendered behind the blur, and then also in front. I've only done this for one of my cell types with lots of colour in it. It works pretty well.
If you have a better approach I'll happily assign you the correct answer.

Zooming an UIView without losing detail

Let's say I have a complex UIView, which is initially on the screen with quite small frame, let's say 80x80.
One of its subviews is an UIImageView displaying an image whose actual resolution is 1024x1024.
When the user tap the UIView i want the view to zoom in almost full screen so that the user can better see the image.
I know already how to scale a UIView to zoom in, my question is the following.
What's the best way to zoom in this view without pixellating the image?
I thought of these options:
I can actually set the frame of the UIView to the full screen size, and normally scale it down, so I'm sure that when it's zoomed in, it will be perfectly detailed. This solution anyway have a strong performance issue, cause moving around many of these scaled down views, will be quite an hit on the CPU/GPU.
I can do it just as I described, so small frame and scale > 1 to zoom in, but in this case will the image be displayed without pixellating?
I can actually set the frame to redisplay the view at the big/small size. In this case the detail will be good, but I have a performance hit here too, because my UIView have around 15 subviews that need complex calculation to relayout, so it's not so "fast" to set the frame.
Which is the best solution? Or do anybody have any other better solution?
Why dont you just have thumbnail representations that are 80x80, and when the user taps on any thumbnail, you transition from your current view containing all the thumbnails to a new view with the +transitionFromView:toView:duration:options:completion: method and simply display a UIImageView with the full resolution image loaded into that new view :)

iOS - Isometric grid image problems

I have a myriad of UIImageViews that act as 'tiles' on a map. They align up next to one another to form a grid of images. The layer of each UIImageView is added as a sublayer of a UIView.
Ordinarily, the grid images are flush against each other, but whenever the UIScrollView that contains the UIView is zoomed in or out, the spaces between the tile images become visible, showing off the grid pattern that I'd like to be invisible.
Any ideas what might be causing this?
Sounds like you're trying to create a CATiledLayer from scratch...?
Why not just use CATiledLayer?

Resources