cocoa touch : animate button on touch

标签 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. mainImg(命名不恰当,因为它是一个按钮)未放置在 View 上 ([self.view addSubview:mainImg])

  2. 我认为您不应该在提交后立即发布。我认为你应该在动画“didStopSelector”处执行此操作,从而使其成为 ivar。

关于 cocoa touch : animate button on touch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4657912/

相关文章:

iphone - Objective-C : Cocoa : 2 sets of variable arguments?

javascript - 如何在元素数组上链接 jQuery addClass() 和 removeClass()

jquery - 如果元素在视口(viewport)中 - 停止滚动动画

javascript - 在 Canvas 元素中对模拟渐变进行动画处理时的随机图案

Android 按钮 setColorFilter 行为

objective-c - 给定过去的 NSDate 和重复间隔,计算从现在开始的下一个事件

objective-c - 带有 block 完成处理程序的自定义模式窗口

objective-c - Objective-C 字符串文字的预处理器宏值

jquery - 即使按钮被禁用,<button> 内的标签也可点击 - 仅限 Webkit

Javafx 如何在 GridPane 中找到特定按钮