gpt4 book ai didi

objective-c - 围绕底轴旋转 UIImageView - Objective-C/iOS

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

我有一个 UIImage View ,我想像翻转时钟一样翻转到平坦。这是水平面的第一部分(我将在其中更改图像或添加新 View 或其他内容)。我的问题是让 View 在底部轴上翻转。它是 100 像素的正方形。我怎样才能让它按底轴旋转。我已经阅读了许多堆栈问题和答案,用谷歌搜索了它,而我的任何答案都不起作用。这是我所拥有的最接近的,它似乎通过在 View 之前移动 View 来翻转,我无法让它翻转但保持静止。

查看 http://www.voyce.com/index.php/2010/04/10/creating-an-ipad-flip-clock-with-core-animation/ 的应用动画部分看起来我的轴是正确的,但我显然没有!

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

boxView.center = CGPointMake(0.5, 1);

boxViewImage.layer.anchorPoint = CGPointMake(0.5, 1);
boxViewImage.layer.transform = CATransform3DMakeRotation(M_PI_2,-1.0,0,0);

[UIView commitAnimations];

boxViewImage 是一个 UIImageView

我需要添加什么才能让它以正确的方式翻转?已经尝试了2天了!

编辑:

我用这个分配了 UIImageView:
CGRect frameRect = CGRectMake(0, 0, 100,100);
boxViewImage = [[UIImageView alloc] initWithFrame:frameRect];
boxViewImage.image = [UIImage imageNamed:@"1.png"];
[self.view addSubview:boxViewImage];

编辑2:

我发现,如果在加载 View 后单击(不是我想要做的)时创建 UIImageView,它也会旋转到我想要的位置。我认为这可能是由于 UINavigationController 具有高度,因为偏移量似乎与它的高度相同!

最佳答案

您的代码中几乎没有错误。

首先我不知道你为什么将 boxView.center 设置为 (0.5, 1)。其次,您不应该在动画 block 内设置 anchor ,第三个 M_PI_2 只是您真正想要的一半动画。

这是解决方案。我使用 UILabel 而不是 UIImageView。

UILabel *testLabel = [[[UILabel alloc] initWithFrame:CGRectMake(20, 20, 100, 100)] autorelease];
testLabel.backgroundColor = [UIColor blackColor];
testLabel.text = @"Test";
testLabel.textColor = [UIColor whiteColor];
[self.view addSubview:testLabel];
testLabel.layer.anchorPoint = CGPointMake(0.5, 1);

[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
testLabel.layer.transform = CATransform3DMakeRotation(M_PI, -1, 0, 0);
}
completion:^(BOOL finished) {
}];

关于objective-c - 围绕底轴旋转 UIImageView - Objective-C/iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7533125/

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