iOS: Animate item twice

余生长醉 提交于 2019-12-12 01:10:04

问题


Just starting out with core graphics. Playing with a simple button and label. I want this label to rotate 180 degrees on each click of the button. It only animates on the first click (the console does write "DONE" on each click, however)

- (IBAction)btnTest:(id)sender
{

    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        lblTest.layer.transform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0);

    }completion:^(BOOL finished) {
        if(finished)
            NSLog(@"DONE");
    }];
}

回答1:


The reason its not working is because on the first button press, the views rotation is set to 180 deg. On the second button press you set the rotation to 180 deg again but since that is the same as the current value of the rotation, nothing happens. What you really want to be doing is setting the rotation to 180 deg + the current rotation. You can achieve this by rotating the current transform by 180 deg with the following change.

lblTest.layer.transform = CATransform3DRotate(lblTest.layer.transform, M_PI,0.0,1.0,0.0);


来源:https://stackoverflow.com/questions/16287491/ios-animate-item-twice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!