可可触摸:触摸动画按钮

时间:2011-01-11 13:05:19

标签: cocoa animation button touch

我有一个全屏按钮(我放在IB中),当用户点击它时,我想要从屏幕滑出一个图像。我知道连接正常,因为我可以在单击按钮时记录某些内容。但是我之前使用过的UIViews和UIImageViews这段代码无效。

-(void) movePatch : (id) sender { 

  mainImg =[[UIButton alloc] init];

 //firing up animation
 [UIView beginAnimations: nil context: NULL]; 
 //setting animation speed
 [UIView setAnimationDuration:2.0   ];

 [mainImg setFrame:CGRectMake (-320.0, 0.0, 320.0, 480.0)];

 //running animations
 [UIView commitAnimations];

 //release mainImg
 [mainImg release];
} 

1 个答案:

答案 0 :(得分:1)

如果这是所有代码,则需要考虑两件事情;

  1. mainImg(不恰当地命名,因为它是一个按钮)没有放在视图上([self.view addSubview:mainImg])

  2. 我认为你不应该在提交后立即发布。我认为你应该在动画''didStopSelector'中做到这一点,从而使它成为一个ivar。