gpt4 book ai didi

ios - CGAffineTransformMakeRotation 再次不起作用

转载 作者:行者123 更新时间:2023-12-01 18:15:37 25 4
gpt4 key购买 nike

我创建了一个 UIView 并将其图层的内容设置为图像。我在这个 View 中添加了一个点击手势。当我点击 View 时,我希望它旋转 180 度,当我单击关闭按钮时,我希望它旋转到原来的度数。但是当我尝试旋转它时它不起作用。

- (void)viewDidLoad
{
[super viewDidLoad];

UIImage *image = [UIImage imageNamed:@"menuArray"];
self.menuView.layer.contents = (__bridge id)image.CGImage;

self.menuView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
[self.menuView addGestureRecognizer:tap];
}
//rotate it 180 degree
- (void)tap
{
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseIn animations:^{
self.menuView.layer.affineTransform = CGAffineTransformMakeRotation(M_PI);
} completion:^(BOOL finished) {

}];
}
//rotate it back. this won't work. I have change the value from M_PI to M_PI_2, M_PI_4. it's not working.
- (IBAction)close:(id)sender
{
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseIn animations:^{
self.menuView.layer.affineTransform = CGAffineTransformMakeRotation(-M_PI);
} completion:^(BOOL finished) {

}];
}

最佳答案

要撤消 affineTransorm,您应该将其设置为常量 affineTransformIdentity ,可以说是 nil 的变换,一个全零矩阵。

所以在你想要旋转的第二种方法中设置self.menuView.layer.affineTransform = CGAffineTransformIdentity

关于ios - CGAffineTransformMakeRotation 再次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22267826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com