2011-01-11 177 views
0

按钮我有一个全屏按钮与欲滑落屏幕,当用户点击在其上的图像(我置于1B)。我知道连接是好的,因为我可以记录按钮被点击时的东西。但是这个代码,我以前用它来移动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

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

  1. 的mainImg(这是不恰当的命名,原因是其是一个按钮)未放置在视图([self.view addSubview:mainImg])

  2. 我不认为你应该释放在提交之后。我想你应该在动画didStopSelector“这样做,从而使其伊娃。

+0

感谢海市蜃楼。在IB,在我的.h文件作为IBOutlet中NSButton * mainImg添加按钮,我还是如你所说,将其添加到视图?所以你认为在这里发布它在CA有机会移动它的位置之前将其销毁? (我知道的命名是关闭的,但我工作了一堆不同的场景,看看有什么效果最好,并厌倦了重新命名它)。 – PruitIgoe 2011-01-11 15:02:25