我有一个全屏按钮(我将其放置在 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];
}
最佳答案
如果这就是全部代码,那么您需要考虑两件事;
mainImg(命名不恰当,因为它是一个按钮)未放置在 View 上 ([self.view addSubview:mainImg])
我认为您不应该在提交后立即发布。我认为你应该在动画“didStopSelector”处执行此操作,从而使其成为 ivar。
关于 cocoa touch : animate button on touch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4657912/