2010-11-01 99 views

回答

25

所以我按下后进入我突然把两个和两个在一起,并认为节拍器样品工作有点像一个摇摆门,这导致了我一些其他的可能性。

这里是我的解决方案:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Set the anchor point and center so the view swings from the upper right 
    swingView.layer.anchorPoint = CGPointMake(1.0, 0.0); 
    swingView.center = CGPointMake(CGRectGetWidth(self.view.bounds), 0.0); 

    // Rotate 90 degrees to hide it off screen 
    CGAffineTransform rotationTransform = CGAffineTransformIdentity; 
    rotationTransform = CGAffineTransformRotate(rotationTransform, DegreesToRadians(90)); 
    swingView.transform = rotationTransform; 
} 

... 

- (void)animateSwing { 

    CGAffineTransform swingTransform = CGAffineTransformIdentity; 
    swingTransform = CGAffineTransformRotate(swingTransform, DegreesToRadians(0)); 

    [UIView beginAnimations:@"swing" context:swingView]; 
    [UIView setAnimationDuration:0.25]; 

    swingView.transform = swingTransform; 

    [UIView commitAnimations]; 
} 

希望这有助于别人呢!

+0

顺便说一下,这个答案是什么导致我从节拍器样本不同的动画。我认为它更清洁一点。 http://stackoverflow.com/questions/929364/how-to-create-iphones-wobbling-icon-effect/930101#930101 – dandax 2010-11-02 13:10:36

+1

我会用90°== M_PI_2 – Ralphleon 2013-02-26 16:41:02

+2

#define DEGREES_RADIANS(angle)((angle)/ 180.0 * M_PI) – 2014-09-04 11:47:56

0

您应该尝试将图层的锚点设置为(0,1),然后设置图层的动画效果。

+0

它们层,当然,视图层。 – tadejsv 2010-11-01 20:00:07

+0

我发现在发布我的问题后不久,layer.anchorPoint和view.center就是罪魁祸首。感谢您及时的回复! – dandax 2010-11-02 13:06:12

-4

你应该试试这个代码:

-(void)doRotationView{ 
[UIView beginAnimations:@"flipping view" context:nil]; 
    [UIView setAnimationDuration:1];  
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft  
          forView:self cache:YES]; 
    if (flagFront == 1) { 
     flagFront =0; 
     [self.viewSecond setHidden:NO]; 
     [self.viewFirst setHidden:YES]; 
    } 
    else{ 
     flagFront =1; 
     [self.viewSecond setHidden:YES]; 
     [self.viewFirst setHidden:NO];   
    } 
    [UIView commitAnimations]; 

}