2013-06-21 64 views
0

我不知道这是否曾被直接问过,但我道歉,如果它。几乎所有我想要完成的是在UIScrollView中旋转UIImageView,这是一个子视图,它与Photos.app中的方式完全相同。旋转UIImageView就像在Photos.app

S.O有许多链接显示旋转图像本身的代码,但我不确定这是否是在Photos.app中完成的。

如果任何人都可以清除它在Photos.app中的做法,那将非常棒!

谢谢!

回答

0

我不明白你的照片应用程序的意思,但没有太多方法来旋转视图。基本上有两种方法:第一种方式将在下面的例子中施加CGTransformation像:

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; 
     [imgView setImage:[UIImage imageNamed:@"polaroid_spacer"]]; 
     [self addSubview: imgView]; 
     [UIView animateWithDuration:0.3f delay:5.f options:UIViewAnimationOptionCurveEaseIn animations:^{ 
      [imgView setTransform:CGAffineTransformMakeRotation(M_PI_2)]; 
     } completion:NULL]; 

另一种方法将是一个CATransform应用于视图的层:

//be sure to include quartz 
#import <QuartzCore/QuartzCore.h> 

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; 

    [imgView setImage:[UIImage imageNamed:@"polaroid_spacer"]]; 

    [self addSubview: imgView]; 

    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"]; 
    [anim setToValue: [NSValue valueWithCATransform3D: CATransform3DMakeRotation(M_PI_2, 0, 0, 1)]]; 
    [anim setDuration: 3.f]; 
    [anim setBeginTime: (CACurrentMediaTime() + 5.f)]; 
    [imgView.layer addAnimation:anim forKey:@"myAwesomeAnim"]; 

两个可以用来实现这一点。但是,如果您对Core Animation不太了解,则应该使用Core Graphics。因为你可以使用UIView动画来获得一些结果更容易。

+0

我的意思是在照片应用程序去看看苹果自己的照片应用程序中的照片,然后单击编辑。然后点击箭头旋转图像,你会看到我的意思。 –

+0

啊,现在我明白了。但是,你可以按照我描述的方式来做到这一点。但他们不只是旋转,而是缩放图像。 – Lukas