我一直在寻找几个小时试图找到一种从右上角动画/旋转UIView 90度的方法。
效果几乎应该像屏幕顶部的摆动门一样。
希望有人可以帮忙!
答案 0 :(得分: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];
}
希望这也有助于其他人!
答案 1 :(得分:0)
您应该尝试将图层的锚点设置为(0,1),然后为图层设置动画。
答案 2 :(得分:-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];
}