i am trying to add animation to move my buttons from left to right.
i have added the following code
[self.view beginAnimations:nil context:nil];
[self.view setAnimationDuration:1.0f];
[button setFrame:newFrame];
[self.view commitAnimations];
but when i build, i see the warning "instance method beginAnimations:context: not found"
I have added QuartzCore framework and included
#import <QuartzCore/CoreAnimation.h>
Can someone please tell what am i missing?
Thank you
Importing quartz headers is not necessary.
beginAnimations:context:
is a class method. You are calling it on an instance of UIView. The same applies for setAnimationDuration
and commitAnimations
. Replace self.view
with UIView
or, better, use block-based animations instead.
Your code, corrected:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[button setFrame:newFrame];
[UIView commitAnimations];
Block-based (iOS4.0 and later):
[UIView animateWithDuration:1.0 animations:^{[button setFrame:newFrame];}];
Based on your comments, you are missing my point. These methods are class methods. you need to call them directly to UIView
- the class . Not to self.view
, which is an instance of UIView . Look at the line of code above - the message is being sent to UIView
. Use the exact line of code above. Copy and paste if you like. I'm not using UIView as a placeholder for "insert a view object here!", it's the code you have to use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.