Fra*_*ank 10 iphone core-animation uibutton caanimation
我正在尝试为UIButton制作动画.但在动画期间,没有与UIButton的互动.预期的行为是能够在移动时单击按钮.这是UIButton和动画的代码片段:
UIImage *cloudImage = [UIImage imageNamed:@"sprite.png"];
UIButton moveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[moveBtn setFrame:CGRectMake(0.0, 80.0, cloudImage.size.width, cloudImage.size.height)];
[moveBtn setImage:cloudImage forState:UIControlStateNormal];
[moveBtn addTarget:self action:@selector(hit:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:moveBtn];
CGPoint newLeftCenter = CGPointMake( 300.0f + moveBtn.frame.size.width / 2.0f, moveBtn.center.y);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0f];
[UIView setAnimationRepeatCount:HUGE_VALF];
moveBtn.center = newLeftCenter;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
hit选择器只显示一个NSLog,以显示按钮是否响应它.任何帮助,将不胜感激.
csa*_*ano 26
尝试将动画选项设置为UIViewAnimationOptionAllowUserInteraction.
[UIView animateWithDuration:.2
delay: 0
options: UIViewAnimationOptionAllowUserInteraction
animations:^{
// animation logic
}
completion:^(BOOL completed) {
// completion logic
}
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5862 次 |
| 最近记录: |