繁体   English   中英

UIButton与CABasicAnimation一起旋转不会移动初始触摸坐标

[英]UIButton rotate with CABasicAnimation does not move initial touch coordinates

我有一个UIView,并在上面添加了UIButton。 我将UIView旋转180度。 旋转UIView后,其中的所有内容(包括按钮)看起来都旋转了。 但是当我点击按钮时。 它仅从其初始位置接收触摸事件。 不是从它出现在屏幕上的位置开始。 这是我的代码-

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((180*M_PI)/180)];
fullRotation.speed = 1.0;
fullRotation.autoreverses = NO;
fullRotation.removedOnCompletion = NO;
fullRotation.fillMode = kCAFillModeForwards;
[_subView.layer addAnimation:fullRotation forKey:@"360"];

您无法在Interface Builder中做到这一点。 您必须从代码中旋转它。 像这样,

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 200)];
    [button addTarget:self action:@selector(selectedButton) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[UIColor purpleColor]];

    CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:((180*M_PI)/180)];
    fullRotation.speed = 1.0;
    fullRotation.autoreverses = NO;
    fullRotation.removedOnCompletion = NO;
    fullRotation.fillMode = kCAFillModeForwards;
    [button.layer addAnimation:fullRotation forKey:@"360"];

    [self.view addSubview:button];

现在, selectedButton将收到每个旋转的UIButton触摸。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM