• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: View swap using "push" animation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: View swap using "push" animation


  • Subject: Re: View swap using "push" animation
  • From: PCWiz <email@hidden>
  • Date: Wed, 11 Nov 2009 11:14:08 -0700

Thanks for your replies :-) Here you can see the distortion.

Before setWantsLayer - http://img21.imageshack.us/img21/43/screenshot20091110at412.png

After - http://img682.imageshack.us/img682/2558/screenshot20091110at424.png

Martin, I tried an NSAnimation subclass and the animation itself works, but the performance is very poor. Here is my code for the subclass:

PushAnimation.h
///////////////////

#import <Cocoa/Cocoa.h>

typedef enum {
	LeftDirection,
	RightDirection
} Direction;

@interface PushAnimation : NSAnimation {
	Direction newDirection;
	NSView *startingView;
	NSView *destinationView;
	NSRect originalRect;
	NSRect destinationRect;
}
@property(retain) NSView *startingView, *destinationView;
@property(readwrite) Direction newDirection;
@property(readwrite) NSRect originalRect, destinationRect;
- (NSRect)destinationFrameForProgress:(float)progress;
- (NSRect)startingFrameForProgress:(float)progress;
@end

////////////////////////
PushAnimation.m
///////////////////////

#import "PushAnimation.h"

@implementation TMPushAnimation
@synthesize startingView, destinationView, newDirection, originalRect, destinationRect;
- (void)startAnimation
{
originalRect = [startingView frame];
// First we need to move the destination view off to one side so that its invisible
if (newDirection == LeftDirection) {
[destinationView setFrame:NSMakeRect(NSMinX(originalRect) - NSWidth (originalRect), NSMinY(originalRect), NSWidth(originalRect), NSHeight (originalRect))];
} else {
[destinationView setFrame:NSMakeRect(NSMaxX(originalRect), NSMinY (originalRect), NSWidth(originalRect), NSHeight(originalRect))];
}
destinationRect = [destinationView frame];
// Unhide the destination view (its going to be invisible because its not in the view area)
[destinationView setHidden:NO];
[super startAnimation];
}
- (void)setCurrentProgress:(float)progress
{
[super setCurrentProgress:progress];
[startingView setFrame:[self startingFrameForProgress:progress]];
[destinationView setFrame:[self destinationFrameForProgress:progress]];
// If the animation is finished we want to hide the starting view (just to make sure)
if (progress == 1.0)
{
[startingView setHidden:YES];
}
}
- (NSRect)startingFrameForProgress:(float)progress
{
NSRect startingViewFrame = originalRect;
// Adjust the X origin of the view based on the animation progress
if (newDirection == LeftDirection) {
startingViewFrame.origin.x = (startingViewFrame.origin.x + startingViewFrame.size.width) * progress;
} else {
startingViewFrame.origin.x = (startingViewFrame.origin.x - startingViewFrame.size.width) * progress;
}
return startingViewFrame;
}


- (NSRect)destinationFrameForProgress:(float)progress
{
NSRect destinationViewFrame = destinationRect;
if (newDirection == LeftDirection) {
destinationViewFrame.origin.x = (destinationViewFrame.origin.x + (destinationViewFrame.size.width * progress));
} else {
destinationViewFrame.origin.x = (destinationViewFrame.origin.x - (destinationViewFrame.size.width * progress));
}
return destinationViewFrame;
}

@end
////////////////////////////


This is how I would use the subclass:

PushAnimation *animation = [[PushAnimation alloc] initWithDuration: 0.35f animationCurve:NSAnimationLinear];
[animation setNewDirection:LeftDirection];
[animation setStartingView:someView];
[animation setDestinationView:anotherView];
[animation setAnimationBlockingMode:NSAnimationNonblocking];
[animation startAnimation];
[animation release];


The performance seems to be quite slow. Here is a video:

http://yfrog.us/0qscreenflowz

It might seem fast upon first view, but if you look closer you can see that there is some lag when switching from the main view with all the content in it to one of the dummy views.

Thanks

On 2009-11-10, at 11:45 PM, Martin Hewitson wrote:



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: View swap using "push" animation
      • From: David Duncan <email@hidden>
    • Re: View swap using "push" animation
      • From: PCWiz <email@hidden>
References: 
 >Re: View swap using "push" animation (From: Matt Neuburg <email@hidden>)
 >Re: View swap using "push" animation (From: Martin Hewitson <email@hidden>)

  • Prev by Date: Re: Create and save a NSPersistentDocument from scratch
  • Next by Date: Re: Create and save a NSPersistentDocument from scratch
  • Previous by thread: Re: View swap using "push" animation
  • Next by thread: Re: View swap using "push" animation
  • Index(es):
    • Date
    • Thread