Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 如何使用UIView创建自定义翻转动画_Ios_Objective C_Animation_Uiview_Core Animation - Fatal编程技术网

Ios 如何使用UIView创建自定义翻转动画

Ios 如何使用UIView创建自定义翻转动画,ios,objective-c,animation,uiview,core-animation,Ios,Objective C,Animation,Uiview,Core Animation,我正在尝试创建一个自定义动画,类似于UIView的默认翻转动画,但没有实际翻转,也没有翻转轴,我希望翻转轴位于左侧而不是中心。下面是一个我试图完成但没有重复的例子: 在代码中,我还将添加UILabel作为子视图和其他一些元素 如果您能提供一个代码示例,将不胜感激 非常感谢您的支持 更新: 使用了@artal提供的示例并获得了UIImageView想要的效果,但我如何才能为UIButton获得相同的示例 已尝试下一个代码: objectivesButton = [[UIButton alloc]

我正在尝试创建一个自定义动画,类似于UIView的默认翻转动画,但没有实际翻转,也没有翻转轴,我希望翻转轴位于左侧而不是中心。下面是一个我试图完成但没有重复的例子:

在代码中,我还将添加UILabel作为子视图和其他一些元素

如果您能提供一个代码示例,将不胜感激 非常感谢您的支持

更新:

使用了@artal提供的示例并获得了UIImageView想要的效果,但我如何才能为UIButton获得相同的示例

已尝试下一个代码:

objectivesButton = [[UIButton alloc] initWithFrame:CGRectMake( 0.25f * [UIScreen mainScreen].bounds.size.width, 0.7f * [UIScreen mainScreen].bounds.size.height, 0.5f * [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height * 0.3f)];
[objectivesButton addTarget:self
                action:@selector(startAnimationButton)
      forControlEvents:UIControlEventTouchUpInside];
objectivesButton.backgroundColor = [UIColor yellowColor];
objectivesButton.layer.anchorPoint = CGPointMake(0, 0.5);
[self.view addSubview:objectivesButton];

- (void)startAnimationButton{

CATransform3D perspectiveTrasnform = CATransform3DIdentity;
perspectiveTrasnform.m34 = -0.004;

CGFloat rotateAngleDeg = 90;
CATransform3D flipTransform = CATransform3DRotate(perspectiveTrasnform, rotateAngleDeg / 180.0 * M_PI, 0, 1.5, 0);
[UIView animateWithDuration:3.0f animations:^()
{
    objectivesButton.layer.transform = flipTransform;
}];

}

通过将透视和旋转变换应用于视图的基础层(3D变换),可以以这种方式设置视图的动画。 要从左侧开始,可以设置层的
锚点。
下面是一个例子:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
imageView.center = CGPointMake(self.view.center.x - imageView.frame.size.width * 0.5, self.view.center.y + imageView.frame.size.height * 0.5);
imageView.layer.anchorPoint = CGPointMake(0, 1);
[self.view addSubview:imageView];

CATransform3D perspectiveTrasnform = CATransform3DIdentity;
perspectiveTrasnform.m34 = -0.004;

CGFloat rotateAngleDeg = 90;
CATransform3D flipTransform = CATransform3DRotate(perspectiveTrasnform, rotateAngleDeg / 180.0 * M_PI, 0, 1, 0);
[UIView animateWithDuration:5 animations:^()
{
    imageView.layer.transform = flipTransform;
}];

请你把你的图像缩小一点,不要那么纯红色好吗?@Azat只是按照你的建议用更方便的方式更改了gif。当然,我只是更新了我的question@LaurStefan此方法适用于任何视图。我在您的问题更新中尝试了该代码,它按预期工作。我不明白它是否对你不起作用。