How to clip scene to screen bounds? - ios

I have a scene, containing layers which are large enough to be off-screen. When I do scene transition (eg. CCTransitionSlideInR) the off-screen part is visible during transition which of course looks ugly. What I want is to clip the scene to screen size. How can I do that?

You could perhaps use this:
https://github.com/njt1982/ClippingNode
The main page references original sources.

Related

How to make view follow my image?

Im making a scene for my game. Right now i`m working on the view for IPhone 5-5c-5s the orientation is in landscape. But the view was not big enough for my scene, so i made the simulated size to freeform so i could choose the width for the scene. (Im using a normal Viewcontroller).
In the game you are supposed to move an image to another image without colliding with obstacles. The users playing the app are going to move an image from one side of the screen all the way over to the other side to the other image to win.
But when my image moves, the view doesnt follow with my image. How do you do that?
I would be so thankful for any answear! Thanks.
I am assuming you are using SpriteKit yeah? The UIView size is not related to the scene size. So changing those will not make your scene any different.
To do what you are describing, you need to read the Apple's Official Documentation on SpriteKit.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Actions/Actions.html
Scroll down to Example: Centering the Scene on a Node
Basically Apple tells you to add a dummy SKNode to put all your world sprites into the scene, and then add another SKNode as "camera" into the dummy node so you can move it around.
If you are targetting only iOS9 and above, you can use SKCameraNode and set:
SKCameraNode *cameraNode = [SKCameraNode new];
cameraNode.name = #"camNode";
self.camera = cameraNode;
Then you add your "character" (that is to be moved together with the camera) into the cameraNode. Then any movement, you need to move the cameraNode instead of the "character".

Leaping image just before Constraint animation

I'm using Constraints within my app and have have a reasonable level of success so far; everything visual object in the gif below is Constrained.
The issue is that when selected, tiles leap to another location before animating to the final, correct destination.
From a code perspective, on a tile click, higher priority positioning Constraints are applied to the tile, the tile is added as a subview to the blue area, then animation is performed.
Can anyone shed a little light on what's happening here?
Thanks
Based on the behavior I'm seeing in your gif, I would guess that when you move the tile views between superviews (the blue area vs. the larger white area), the view jumps to it's current frame position (within the coordinate system of the old superview), but now in the coordinate system of the new superview.
The solution, I think, would be to translate the final position in the new superview to a position in the current superview, perform the animation, and only when the animation completes would you move the view to it's new superview.
Does that make sense?

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 :)

Problems rotating in the middle of a pan with UIViewPageController-based slide show

I have an image slide-show viewer that uses a UIPageViewController to present the images.
The image-view viewer ViewController is pretty simple -- a top-level view containing a UIScrollView containing a UIImageView. On initial image presentation or when the device is rotated the image is aspect-fitted to the view dimensions and centered. It works fine except for a problem which happens on both iOS 7 and iOS 6.
If I am in the middle of panning to change images and two images are on the screen and I then rotate the device it sometimes (maybe always?) messes up the display of one or more images. The previously-centered image appears in the wrong place on the screen and this persists when rotated and zoomed.
The only thing I can find wrong when this happens is that the center property of the UIImageView is not, in fact, the center of the frame. If I change the center property of the UIImageView in viewDidAppear to be the center of the possibly-scaled UIImageView then the images seem to display correctly in all cases.
Does this sound like the effect of some familiar mistake that I'm making?
Edit to respond to the question:
I don't do anything in the willRotate or didRotate methods.
In viewDidLayoutSubviews I aspect-fit the image into the current UIScrollView bounds (which is the full top-level view which is the full screen) and center it. This takes care of both the initial presentation and rotations. I don't see any problems in "normal" rotation situations. The problem occurs only when I rotate with two of the pageViewController's children views both partly onscreen at once. I can "fix" the problem in all cases but surely I'm doing something wrong.
Edit 2
I've discovered another anomaly that occurs less frequently when rotating the device while panning with 2 images onscreen. Best explained by an example:
The page view controller is being used to display one image in a sequence of images from left to right of A B C. Image B is onscreen. During a pan to the left you see part of both images A and B. If the pan to image A is nearly complete, i.e. B is nearly offscreen, and you rotate the device then image B normally ends up onscreen (it never rotates still showing the partial pan), but sometimes image C ends up being displayed -- as though you had panned in the other direction. Anybody else see this kind of behavior?
What are you doing in your UIViewController to prepare for the rotation?
– willRotateToInterfaceOrientation:duration:
And then how do you recover once the rotation has finished?
- didRotateFromInterfaceOrientation
These calls are provided specifically so you have a chance to get ready for a rotation, and then to put everything back to normal once it completes.

CATiledLayer is being rendered underneath a UIView

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.

Resources