我已经成功创建了一个从tabBar选择中显示的图标菜单。您可以在纵向或横向中查看此菜单。
由于屏幕上的空间,我已经制作了它,因此在纵向中你可以查看4x4图标..但是由于在横向观看时的尺寸,这样的效果不好......所以我已经做到了这样你就可以了因为这个,我决定为菜单创建两个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];
答案 0 :(得分:7)
使用UIView方法“transitionFromView”,而不是单独的淡入和淡出动画。这是一个例子:
[UIView transitionFromView:jumpBarContainerLandscape
toView:jumpBarContainerPortrait
duration:crossDissolveTime
options:UIViewAnimationOptionTransitionCrossDissolve
completion:NULL];