ios – 如何激活UIImageViews,如舱门打开

ios – 如何激活UIImageViews,如舱门打开,第1张

概述我正在尝试创建一个动画,看起来像向用户开放的2个法式门(或2个舱口门). 我尝试使用内置的UIViewAnimationOptionTransitionFlipFromRight转换,但转换的起源似乎是UIImageView的中心,而不是左边缘.基本上我有两个UIImageViews,每个填充屏幕.我希望动画看起来像UIImageViews从屏幕中心提升到边缘. [UIView transitio 我正在尝试创建一个动画,看起来像向用户开放的2个法式门(或2个舱口门).

我尝试使用内置的UIVIEwAnimationoptionTransitionFlipFromright转换,但转换的起源似乎是UIImageVIEw的中心,而不是左边缘.基本上我有两个UIImageVIEws,每个填充屏幕.我希望动画看起来像UIImageVIEws从屏幕中心提升到边缘.

[UIVIEw TransitionWithVIEw:leftVIEw                  duration:1.0                   options:UIVIEwAnimationoptionTransitionFlipFromright                                           animations:^ { leftVIEw.Alpha = 0; }                completion:^(BOol finished) {                    [leftVIEw removeFromSupervIEw];                 }];

有没有人做过这样的事情?任何帮助都是极好的!

更新:
工作代码感谢Nick Lockwood

leftVIEw.layer.anchorPoint = CGPointMake(0,0.5); // hinge around the left edgeleftVIEw.frame = CGRectMake(0,160,460); //reset vIEw positionrightVIEw.layer.anchorPoint = CGPointMake(1.0,0.5); //hinge around the right edgerightVIEw.frame = CGRectMake(160,460); //reset vIEw position[UIVIEw animateWithDuration:0.75 animations:^{    CAtransform3D lefttransform = CAtransform3DIDentity;    lefttransform.m34 = -1.0f/500; //dark magic to set the 3D perspective    lefttransform = CAtransform3DRotate(lefttransform,-M_PI_2,1,0);    leftVIEw.layer.transform = lefttransform;    CAtransform3D righttransform = CAtransform3DIDentity;    righttransform.m34 = -1.0f/500; //dark magic to set the 3D perspective    righttransform = CAtransform3DRotate(righttransform,M_PI_2,0);    rightVIEw.layer.transform = righttransform;}];
解决方法 首先将QuartzCore库添加到您的项目,然后将#import< QuartzCore / QuartzCore.h>

每个视图都有一个层属性,子属性是可动画的.在这里,您可以找到所有非常酷的东西,当涉及到动画功能(我建议您阅读可以设置的CALayer类属性 – 它会吹动你的头脑 – 任何视图上的动态柔和的阴影?)

无论如何,回到主题.要旋转你的门打开3D,首先定位他们,如果他们被关闭,所以每个门填充一半的屏幕.

现在设置它们的vIEw.layer.anchorPoint属性如下

leftDoorVIEw.layer.anchorPoint = CGPoint(0,0.5); // hinge around the left edgerightDoorVIEw.layer.anchorPoint = CGPoint(1.0,0.5); // hinge around the right edge

现在应用以下动画

[UIVIEw animateWithDuration:0.5 animations:^{   CAtransform3D lefttransform = CAtransform3DIDentity;   lefttransform.m34 = -1.0f/500; //dark magic to set the 3D perspective   lefttransform = CAtransform3DRotate(lefttransform,0); //rotate 90 degrees about the Y axis   leftDoorVIEw.layer.transform = lefttransform;   //do the same thing but mirrored for the right door,that probably just means using -M_PI_2 for the angle. If you don't kNow what PI is,Google "radians"}];

那应该这样做.

免责声明:我没有真正测试过这个,所以角度可能会倒退,而且透视角度可能是螺旋式的,但至少应该是一个好的开始.

更新:好奇心越来越好.这里是完整的工作代码(这假设左右门被布置在nib文件中的关闭位置):

- (voID)vIEwDIDLoad{    [super vIEwDIDLoad];    leftDoorVIEw.layer.anchorPoint = CGPointMake(0,0.5); // hinge around the left edge    leftDoorVIEw.center = CGPointMake(0.0,self.vIEw.bounds.size.height/2.0); //compensate for anchor offset    rightDoorVIEw.layer.anchorPoint = CGPointMake(1.0,0.5); // hinge around the right edge    rightDoorVIEw.center = CGPointMake(self.vIEw.bounds.size.wIDth,self.vIEw.bounds.size.height/2.0); //compensate for anchor offset}- (IBAction)open{    CAtransform3D transform = CAtransform3DIDentity;    transform.m34 = -1.0f/500;    leftDoorVIEw.layer.transform = transform;    rightDoorVIEw.layer.transform = transform;    [UIVIEw animateWithDuration:0.5 animations:^{        leftDoorVIEw.layer.transform = CAtransform3DRotate(transform,0);        rightDoorVIEw.layer.transform = CAtransform3DRotate(transform,0);    }];}- (IBAction)close{    [UIVIEw animateWithDuration:0.5 animations:^{        CAtransform3D transform = CAtransform3DIDentity;        transform.m34 = -1.0f/500;        leftDoorVIEw.layer.transform = transform;        rightDoorVIEw.layer.transform = transform;    }];}
总结

以上是内存溢出为你收集整理的ios – 如何激活UIImageViews,如舱门打开全部内容,希望文章能够帮你解决ios – 如何激活UIImageViews,如舱门打开所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1113077.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存