设置 UIImageView 锚点,而不更改界面生成器中的位置



为了使图像从左到右显示,我设置锚点如下:

myImageView.layer.anchorPoint = CGPointMake(0.0f, 1.0f);

然后对其进行动画处理:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myImageView.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];

动画效果很好,但是通过更改图像的锚点,图像不会出现在界面生成器中设置的位置,当设置锚点时,它会移动很多。

有谁知道是否有办法在不更改界面生成器中图像位置的情况下设置锚点或实现此效果?

谢谢!

在 ViewDidLoad 中:只需初始化您的 ImageView 帧:

[ImageView setFrame:CGRectMake(900, 0, 69, 39)];

并编写以下代码:

    [UIView animateWithDuration:0.5 
                          delay:0.1 
                        options:UIViewAnimationOptionTransitionCurlDown
                     animations:^{
                         //animation code
                         ImageView.frame = CGRectMake(0, 0, 320, 345);
                     } completion:^(BOOL finished) {
                         //completion code
                     }];

最新更新