Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an slide animation while bringing an custom view in Cocoa?

Tags:

macos

cocoa

I'm developing an app where when clicking to a button, custom view should slide from a side. Actually just a window appears, but I'd like to have something like iOS navigation controller. How this can be done? This is for an Mac OS X app.

like image 756
pmerino Avatar asked Aug 02 '11 17:08

pmerino


People also ask

What is custom animation?

Custom AnimationA set of effects which can be applied to objects in PowerPoint so that they will animate in the Slide Show . They can be added under the Custom Animation function or through the use of Visual Basic for Applications (VBA).

How do you animate a view in Swift?

To be exact, whenever you want to animate the view, you actually call layoutIfNeeded on the superview of that view. Try this instead: UIView. animate(withDuration: 0.1, delay: 0.1, options: UIViewAnimationOptions.


2 Answers

You can use a Core Animation transition. You need to turn on layer backing for the parent view, and then you can do

[[parentView animator] replaceSubview:oldView with:newView];

By default that will crossfade the views, but if you want to change it to a slide animation then you'd add the appropriate CATransition to the animations dictionary.

- (CATransition *)slideAnimation
{
    CATransition *transition = [CATransition animation];
    [transition setType:kCATransitionMoveIn];
    [transition setSubtype:kCATransitionFromRight];
    return transition;
}

and then to set that animation in your parentView

...
[parentView setAnimations:[NSDictionary dictionaryWithObject:[self slideAnimation] forKey:@"subviews"];
...
like image 197
iain Avatar answered Sep 28 '22 03:09

iain


You can use animator. Here is a sample:

NSPoint startPoint = NSMakePoint(NSWidth([[self window] frame]), NSHeight([[self window] frame]) - NSHeight([view frame]));
[view setFrameOrigin:startPoint];
NSPoint endPoint = NSMakePoint(0.0f, startPoint.y);
[[view animator] setFrameOrigin:endPoint];
like image 45
VenoMKO Avatar answered Sep 28 '22 03:09

VenoMKO