开发者

cocoa touch: animate button on touch

开发者 https://www.devze.com 2023-02-03 20:25 出处:网络
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 cli

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;

  1. the mainImg (which is inappropriately named, becuase it is a button) is not placed on the view ([self.view addSubview:mainImg])

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消