cocoa touch: animate button on touch
I have a full screen button (which I placed in IB) with an image that I want to slide off screen when the user clicks on it. I know the connections are ok as I can log something when the button is clicked. But this code, which I have used before to move UIViews and UIImageViews is not working.
-(void) movePatch : (id) sender {
mainImg =[[UIButton alloc] init];
//firing up animation
[UIView beginAnimations: nil context: NULL];
//setting animation speed
[UIView se开发者_开发百科tAnimationDuration:2.0 ];
[mainImg setFrame:CGRectMake (-320.0, 0.0, 320.0, 480.0)];
//running animations
[UIView commitAnimations];
//release mainImg
[mainImg release];
}
If this is all the code, there are two things you need to consider;
the mainImg (which is inappropriately named, becuase it is a button) is not placed on the view ([self.view addSubview:mainImg])
I don't think you should release right after the commit. I think you should do this at the animations' 'didStopSelector', and thus make it an ivar.
精彩评论