In fact, if you don't want animation used, you have to explicitly turn animation off. There is no animator proxy available in a CALayer object, but rather animation is always used when you make an explicit change to a property. setAnimations: setFrame:newFrame] Layer ResizingĪnimating a layer's frame is a bit different from doing the same in windows and views. Explicitly Animating Frame Origin and Size CABasicAnimation *originAnimation = [ CABasicAnimation animationWithKeyPath: setFromValue:[ NSValueĬABasicAnimation *sizeAnimation = [ CABasicAnimation animationWithKeyPath: setFromValue: Listing 3-4 shows how to animate both of these properties. If you want to use explicit animation, instead of animating the frame, animate the frameOrigin and the frameSize. The only difference between this code and the code in Listing 3-1 is the object we're calling –setFrame on-a view in this case. Animate View Frame Change in an NSAnimationContext ![]() You can call -setFrame on a view using the same code you used for a window, as shown in Listing 3-3. Views can be resized the same as windows can, but the keypath you use differs. The visual effect is identical to what you see occur when running the code in Listing 3-1. Adding an Animation to the Window Animations Dictionary CABasicAnimation *animation = Take a look at Listing 3-2 to see how to create, add, and run a basic animation on a window. As an alternative to calling –setFrame on the window animator proxy, we can create a CABasicAnimation and animate the frame property. As you see in the next section, this grouping mechanism is also what you use when you want to change the duration of an animation for an NSView.īasic animation using Core Animation can also be used on windows and views, but there is a slight difference in how the animation is set up. This causes the frame to change over the course of 5 seconds rather than the default of 0.25 seconds. Wrap Frame Change in an NSAnimationContext If we wrap the call to –setFrame in an NSAnimationContext, the animation runs at the duration we specify. If you want to change the duration, use an NSAnimationContext object, which is the NSView/ NSWindow counterpart to the CATransaction. This makes it simple to animate the frame.īy default, the animation plays back over the course of 0.25 seconds. If you want to move the window to a different position on the screen, for instance, you can either call - (void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews (notice the missing third parameter) on the animator proxy object, or you can add an animation to the animations dictionary of the window itself.įirst, let's look at how to use the animator proxy. When you call the animator, it animates the parameter you specified, but the parameter is the catch. NSWindow has an animator proxy just like NSView. Keep several things in mind when doing so. There may be times, however, when you want more control over animating windows. For many cases when resizing, you can use the built-in functionality and you probably should. With this built-in window frame resizing capability, why would you need to use Core Animation for changing a window's frame? The answer is, simply, you don't. They both have a method called –setFrame. ![]() This call is different than what you use for changing the frame in both NSViews and CALayers. If this last parameter is set to NO, the change to the new frame happens immediately rather than progressively with animation. The second parameter tells the window to call –displayIfNeeded on all of its subviews, and the third parameter tells the window to animate the transition from its current frame to the frame specified in the first parameter. The first parameter is the new frame you are animating to. Since the first version of Mac OS X, the ability to animate a window's frame has been available to developers in the method -(void)setFrame:(NSRect)windowFrame display:(BOOL)displayViews animate:(BOOL)performAnimation. In this section, we discuss one of the most common animations you will likely want to implement-frame resizing. The idea behind animation in windows, views, and layers is the same however, the implementation differs. Learn More Buy The Differences Between Window, View, and Layer Animation Core Animation: Simplified Animation Techniques for Mac and iPhone Development
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |