2012-07-13 36 views
0

我想知道iOS中的动态动画时,我打开方向。例如。在我的iPad上,动画在菜单中看起来非常“真实”。元素(应用程序,文件夹,码头,背景图像,状态栏......)似乎以完美的审美方式滑动到正确的位置......
但是在App Store中,我发现了一个偏差,因为应用程序列表另一种安排。
我的一个大问题:orientationChangeAnimation是一个错觉还是真的如此动态?在App Store中,它看起来像是实际的屏幕正在转动,同时它的alpha值正在降低,并且改变后的屏幕的风景/肖像方向也会做相同的反转(在增加alpha值的同时转向)。iOS - 方向更改 - 错觉或元素移动?

回答

1

事实上,Springboard确实会移动东西(如码头),并且它还会交叉淡化物品(如大部分应用图标)。

由于viewWillLayoutSubviewswillRotateToInterfaceOrientation在旋转期间在动画块中被调用,因此您可以简单地将新值赋给动画属性,如alpha和frame。除非你想明确控制时间,否则不需要明确的调用;旋转过程中,iOS会自动为您制作动画。

作为示例,在下面的代码中,红色和绿色方块在屏幕中央交叉淡化,蓝色方块在旋转过程中在左上角和顶部中心之间移动。

CGRect b = self.view.bounds; 
self.greenLabel = [[UILabel alloc] initWithFrame:CGRectMake(b.size.width/2 - 50, b.size.height/2 - 50, 100, 100)]; 
self.greenLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 
self.greenLabel.backgroundColor = [UIColor greenColor]; 
[self.view addSubview:self.greenLabel]; 

self.redLabel = [[UILabel alloc] initWithFrame:self.greenLabel.frame]; 
self.redLabel.autoresizingMask = self.greenLabel.autoresizingMask; 
self.redLabel.backgroundColor = [UIColor redColor]; 
[self.view addSubview:self.redLabel]; 

self.blueLabel = [[UILabel alloc] init]; 
self.blueLabel.backgroundColor = [UIColor blueColor]; 
[self.view addSubview:self.blueLabel]; 

... 

- (void)viewWillLayoutSubviews { 
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { 
    self.greenLabel.alpha = 0; 
    self.redLabel.alpha = 1; 
    self.blueLabel.frame = CGRectMake((self.view.bounds.size.width - 100)/2, 20, 100, 100); 
    } else { 
    self.greenLabel.alpha = 1; 
    self.redLabel.alpha = 0; 
    self.blueLabel.frame = CGRectMake(20, 20, 100, 100); 
    } 
} 
1

是的,这真的很容易做,我在很多我的应用程序做了类似的事情。如果你想复制的功能,你可以这样做:

在willRotateToInterfaceOrientation方法或在viewWillLayoutSubviews方法,你可以做以下任一:

//Fade out 
[UIView animateWithDuration:0.3 animations:^ { 
    yourController.view.alpha = 0.2; 
}]; 

//Fade In 
[UIView animateWithDuration:0.3 animations:^ { 
    yourController.view.alpha = 1.0; 
}]; 

//Fade out fade in 
[UIView animateWithDuration:0.15 animations:^ { 
    yourController.view.alpha = 0.2; 
}]; 

[UIView animateWithDuration:0.15 animations:^ { 
    yourController.view.alpha = 1.0; 
}]; 

干杯,

山姆