• 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: Using NSAnimation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSAnimation


  • Subject: Re: Using NSAnimation
  • From: Matt Long <email@hidden>
  • Date: Wed, 26 Nov 2008 12:19:27 -0700

Core Animation using layers would make this simpler for you, I think. You can still get the click from the layer backed view, but then add your image to the view's layer tree as a layer. Animating a layer is trivial in CA.

I did a blog post on how to animate a layer to the clicked point in the view. Shows you how to get the current location on the view while in-flight as well. http://www.cimgf.com/2008/11/05/core-animation-tutorial-interrupting-animation-progress/ . The layer that I animate in the post demo project doesn't have an image in it, but just look at setting the contents field in the layer (CALayer docs) and you'll have what you need.

This probably won't help you if you need to stick with NSAnimation, but et me know if you have CA questions.

-Matt



On Nov 26, 2008, at 7:51 AM, Hrishikesh Muruk wrote:

I have a basic question about using NSAnimation. Here is what I am trying to do: My program shows a custom view and I want to animate an NSImage within that custom view. When the mouse is clicked within the program I want to move (animate) the image to a new point in the window.


I have subclassed NSAnimation into MyAnim and I have overloaded the method "-(void)setCurrentProgress:(NSAnimationProgress)progress". My program is organized in this fashion.


I have a custom view class MyView which has pointers to my data objects (an NSImage in this case) and my animation object myAnim. It also has a pointer to my custom view object MyView.

On a mouse click I send the message
[myAnim startAnimation];

@interface MyView : NSView {

	NSImage *myObj;
	MyAnim *myAnim;
}


I want the animation to begin when the mouse is clicked so I have overloaded the "-mouseDown" method to call [myAnim startAnimation];. I plan to animate my image by changing its position from within - setCurrentProgress. My problem - how do I access myObj from within the method -setCurrentProgress (which is inside MyAnim). I could do something like:


(in file MyAnim.m)
-(void)setCurrentProgress:(NSAnimationProgress)progress {
	NSImage * tmpImg = [super valueForKey:@"myObj"];
}

But it looks a little bit like a hack.

My questions:
1. Is there a better way to access myObj from MyAnim?
2. Once I change the position of myObj how do I get the view to redraw the image?


Hrishi

_______________________________________________

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


References: 
 >Using NSAnimation (From: Hrishikesh Muruk <email@hidden>)

  • Prev by Date: Re: to get handle to "File/1.jpg"
  • Next by Date: Re: NSImage/NSImageView/GIF Saving an Animated GIF from NSImageView
  • Previous by thread: Using NSAnimation
  • Next by thread: advice needed please
  • Index(es):
    • Date
    • Thread