我已經成功地創建了一個圖標菜單,顯示從tabBar選擇。您可以以縱向或橫向查看此菜單。動畫UIViews獲得交叉淡入淡出效果不太好
因爲屏幕上的空間我已經使它在肖像中,你可以查看4x4圖標..但是由於在風景中查看時的尺寸,這種劑量不能很好地工作..所以我已經做到了讓你可以查看2行6和1行4.因此,我決定爲菜單創建兩個UIViews,當設備旋轉時,我在兩個視圖之間切換。
即如果肖像當前和設備是旋轉負載景觀和卸載肖像,反之亦然。
這是我使用的改變對設備旋轉視圖的代碼,這個工作完全正常(也許不是最好的代碼,但它的我能做的最好的)
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
{
if([jumpBarContainerLandscape superview])
{
// Device is changing from landscape to protrait change views to fit
// load landscape view
jumpBarContainerPortrait = [[UIView alloc] initWithFrame:CGRectMake(0.0, (367 - jumpBarHeightPortrait), 320.0, (jumpBarHeightPortrait + 49.0))];
jumpBarContainerPortrait.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
jumpBarContainerPortrait.alpha = 0.0;
// add jumpbar container to view
[self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];
[UIView animateWithDuration:0.2
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
jumpBarContainerLandscape.alpha = 0.0;
} completion:^(BOOL finished) {
if (finished) {
}
}];
[UIView animateWithDuration:0.2
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
jumpBarContainerPortrait.alpha = 1.0;
} completion:^(BOOL finished) {
if (finished) {
// remove subView for superView
[jumpBarContainerLandscape removeFromSuperview];
}
}];
}
}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)
{
if ([jumpBarContainerPortrait superview])
{
// Device is changing from portrait to landscape change views to fit
// load landscape view
jumpBarContainerLandscape = [[UIView alloc] initWithFrame:CGRectMake(0.0, (207 - jumpBarHeightLandscape), 480.0, (jumpBarHeightLandscape + 49.0))];
jumpBarContainerLandscape.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
jumpBarContainerLandscape.alpha = 0.0;
// add jumpbar container to view
[self.view insertSubview:jumpBarContainerLandscape belowSubview:actionTabBar];
// fade out
[UIView animateWithDuration:0.2
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
jumpBarContainerPortrait.alpha = 0.0;
} completion:^(BOOL finished) {
if (finished) {
}
}];
// fade in
[UIView animateWithDuration:0.2
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
jumpBarContainerLandscape.alpha = 1.0;
} completion:^(BOOL finished) {
if (finished) {
// remove subView for superView
[jumpBarContainerPortrait removeFromSuperview];
}
}];
}
}
現在的問題我有兩個UIViews之間的動畫是相當醜陋的,它不是很流暢,你可以看到兩個不同的意見,在動畫等,這是不受歡迎的。我想知道如果有人可以想出一個很好的方法來交叉淡入兩個製作它看起來稍微平滑等...
任何幫助將不勝感激。
編輯:
所以我試着建立一個CATransaction,但是我有一個線上的錯誤給我這個錯誤爲「UIView的」無可見@interface聲明選擇「jumpBarContainerPortrait」我已經加入到我得到這個錯誤低於..任何幫助將不勝感激
[CATransaction begin];
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = 3.50;
[self.view insertSubview:jumpBarContainerPortrait belowSubview:actionTabBar];
[[self.view jumpBarContainerPortrait] addAnimation:animation forKey:@"Fade"]; // Error is happening here!
[CATransaction commit];
您是否嘗試過使用'CATransition'而不是'kCATransitionFade'類型。 – sooper