User interaction on an animated UIButton

一个人想着一个人 提交于 2019-12-05 14:09:33

Touch events do not work correctly in iOS while a view is animating. You can touch views when it sits at the source location, or touch views when it sits at the destination location, but touch events will not trigger correctly for the position the view is at while it is animating.

To deal with this, you must either disable user interaction on the view while it is animating and forget about the idea of touching things while they animate, or you can cover the animating view with another stationary view that has user interaction enabled and thus intercepts the touch events, then tries to figure out if the touch event is in the animating views area. You can do this using:

CGPoint animatingViewPosition = [(CALayer*)[animatingView.layer presentationLayer] position];
iDilip

You can use,

button.frame = CGRectMake(100, 100, 60, 40);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:4.0];
button.frame = CGRectMake(100, 300, 60, 40);    
[UIView commitAnimations];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!