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

Des*_*023 1 animation core-animation objective-c uiimageview ios

我有一个UIImage视图,我想像翻转时钟那样翻转为扁平状态.这是水平面的第一部分(我将更改图像或添加新视图或其他内容).我的问题是让视图在底部轴上翻转.这是100px平方.如何让它通过底轴旋转.我已经阅读了许多堆栈问题和答案,谷歌搜索它和什么回答我没有工作.这是我最接近的,它似乎在它之前移动视图翻转,我不能让它翻转但保持静止.

看看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];
Run Code Online (Sandbox Code Playgroud)

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];
Run Code Online (Sandbox Code Playgroud)

编辑2:

我发现如果我在加载视图后单击(不是我想要做的)时创建我的UIImageView,它也会在我想要的地方旋转.我认为这可能是由于UINavigationController有一个高度,因为偏移似乎与它的高度相同!

Spl*_*lit 5

你的代码中有一些问题.

首先我不知道为什么你将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) {
                 }];
Run Code Online (Sandbox Code Playgroud)