Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
围绕底轴旋转UIImageView-Objective-C/iOS_Objective C_Ios_Animation_Uiimageview_Core Animation - Fatal编程技术网

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

围绕底轴旋转UIImageView-Objective-C/iOS,objective-c,ios,animation,uiimageview,core-animation,Objective C,Ios,Animation,Uiimageview,Core Animation,我有一个UIImage视图,我想像翻转时钟一样翻转到平面。这是水平面的第一部分,我将在这里更改图像或添加新视图或其他内容。我的问题是让视图在底轴上翻转。它是100像素见方的。如何使其沿底部轴旋转。我读过很多堆栈问题和答案,用谷歌搜索了一下,我得到的答案都不起作用。这是我拥有的最接近的一个,它似乎通过在视图翻转之前移动视图来翻转,我无法让它翻转,但保持静止 看看应用动画部分,我的轴似乎是正确的,但我显然没有 [UIView beginAnimations:nil context:nil]; [U

我有一个UIImage视图,我想像翻转时钟一样翻转到平面。这是水平面的第一部分,我将在这里更改图像或添加新视图或其他内容。我的问题是让视图在底轴上翻转。它是100像素见方的。如何使其沿底部轴旋转。我读过很多堆栈问题和答案,用谷歌搜索了一下,我得到的答案都不起作用。这是我拥有的最接近的一个,它似乎通过在视图翻转之前移动视图来翻转,我无法让它翻转,但保持静止

看看应用动画部分,我的轴似乎是正确的,但我显然没有

[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

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

编辑:

我为UIImageView分配了以下内容:

CGRect frameRect = CGRectMake(0, 0, 100,100);
boxViewImage = [[UIImageView alloc] initWithFrame:frameRect];
boxViewImage.image =  [UIImage imageNamed:@"1.png"];
[self.view addSubview:boxViewImage];
编辑2:


我发现,如果我在加载视图后单击不想执行的操作时创建UIImageView,它也会在我想要的位置旋转。我认为这可能是因为UINavigationController有一个高度,因为偏移量似乎与其高度相同

代码中几乎没有错误

首先,我不知道为什么要将boxView.center设置为0.5,1。第二,不应该在动画块内设置锚点,第三个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) {
                 }];

您的代码中几乎没有什么错误

首先,我不知道为什么要将boxView.center设置为0.5,1。第二,不应该在动画块内设置锚点,第三个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) {
                 }];

实际上,我用语音教程制作了一个小框架。也许这有助于:

它包含三个类:

JDFlipNumber查看单个动画数字 JDGroupedFlipNumberView查看分组和链接的可选择数量的FlipView以获得更高的数字 JDDateCountDownFlip查看日期倒计时,只需初始化一个日期,设置一个框架,就可以了。 在任何情况下,您只需执行三个步骤:

初始化类 设置整型值或日期 启动动画
实际上,我用语音教程制作了一个小框架。也许这有助于:

它包含三个类:

JDFlipNumber查看单个动画数字 JDGroupedFlipNumberView查看分组和链接的可选择数量的FlipView以获得更高的数字 JDDateCountDownFlip查看日期倒计时,只需初始化一个日期,设置一个框架,就可以了。 在任何情况下,您只需执行三个步骤:

初始化类 设置整型值或日期 启动动画
谢谢,这已经开始澄清问题,但出于某种原因,它似乎仍然从基线旋转约20%/20px。导航控制器会对坐标有任何影响吗?ps我使用M_PI_2,因为我要在高点交换图像。也许这不是最好的办法!哦,我明白了。20%是个谜。我不知道它为什么这么做。我发送的代码在我的项目中运行良好。谢谢您的尝试。它让我比以前更接近了:DThanks,这已经开始澄清问题,但出于某种原因,它似乎仍然从基线旋转20%/20px左右。导航控制器会对坐标有任何影响吗?ps我使用M_PI_2,因为我要在高点交换图像。也许这不是最好的办法!哦,我明白了。20%是个谜。我不知道它为什么这么做。我发送的代码在我的项目中运行良好。谢谢您的尝试。这让我比以前更亲近了:D