2012-07-13 35 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; 
}]; 

乾杯,

山姆