I just realized that the animation only seems to be slow when I'm running screen capture software to capture video from my screen. Is this just a coincidence or is it a real possibility that the capture is slowing the animation down?

On 2009-11-11, at 11:14 AM, PCWiz wrote:

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to