1

在 iphone 启动画面上工作,我借助一些图像制作了自定义动画,这些图像将在横向模式下出现在我的启动画面上,然后我希望当我的第二个视图加载时它应该以纵向模式显示,但我无法实现这个,这是我的代码:

@interface SplashViewController : UIViewController
 {
 IBOutlet   UIImageView *ani;
  NSMutableArray *arr;
}
@property(strong,nonatomic)UIImageView *ani; 
@property(strong,nonatomic)NSMutableArray *arr;
-(void)switchView;
@end

#import "SecondView.h"
@implementation SplashViewController
@synthesize ani,arr;  


 - (void)viewDidLoad
{

arr = [NSMutableArray arrayWithObjects:[UIImage imageNamed:@"image_1.png"],
       [UIImage imageNamed:@"image_2.png"],[UIImage imageNamed:@"image_3.png"], 
       [UIImage imageNamed:@"image_4.png"],[UIImage imageNamed:@"image_5.png"],
       [UIImage imageNamed:@"image_6.png"],[UIImage imageNamed:@"image_7.png"],
       [UIImage imageNamed:@"image_8.png"],[UIImage imageNamed:@"image_9.png"],
       [UIImage imageNamed:@"image_10.png"],[UIImage imageNamed:@"image_11.png"],
       [UIImage imageNamed:@"image_12.png"],[UIImage imageNamed:@"image_13.png"],
       [UIImage imageNamed:@"image_14.png"],[UIImage imageNamed:@"image_15.png"],
       [UIImage imageNamed:@"image_16.png"],[UIImage imageNamed:@"image_17.png"],
       [UIImage imageNamed:@"image_18.png"],[UIImage imageNamed:@"image_19.png"],       
         [UIImage imageNamed:@"image_20.png"],nil];


   [ani setImage:[UIImage imageNamed:@"image_20.png"]];

ani.animationImages=arr;

ani.animationDuration=10;
 //   ani.animationRepeatCount=1.0;
[ani startAnimating];
[self performSelector:@selector(switchView) withObject:nil afterDelay:15.0];


          [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.
}


-(void)switchView
{
 [ani stopAnimating];
 SecondView *sec=[[SecondView alloc]init];
[self.view addSubview:sec.view];

}

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

我在第二个视图中使用了一个按钮以从中删除启动视图,因此当我们单击第二个视图上的按钮时,启动视图应该关闭,或者可以在加载第二个视图时执行相同操作,但我无法实现它

 -(IBAction)btn:(id)sender
{
 // UIViewController 
[self.view removeFromSuperview];
 }

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

注意:我不想为我的 Flash 使用 Default.png 图像视图但启动视图仍然出现在视图的背面..我只有模拟器要测试..有人可以帮我解决这个问题吗?

4

4 回答 4

0

您可以在 switchView 方法中使用以下代码

-(void)switchView
{
 [ani stopAnimating];
 SecondView *sec=[[SecondView alloc]init];

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

appDelegate.window.rootViewController = sec;

}
于 2012-09-13T12:09:05.113 回答
0

你不应该在你的 spalshScreenController 中实现视图的切换:这不是它的责任,最好在你的appdelegate applicationDidFinishLaunching方法中做到这一点:

-(void)applicationDidFinishLaunching:(UIApplication *)application {
     splashViewController = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
     [window addSubview:splashViewController.view];
     [window makeKeyAndVisible];

  }

并添加一个响应您按下的按钮的方法,这将呈现您的第二个控制器的视图。

-(void)onSlashScreenDone{

     [splashViewController.view removeFromSuperview];
     [window addSubview:[youOtherController view]];
     [window makeKeyAndVisible];

}

shouldAutorotateToInterfaceOrientation通过实现该方法,允许您希望在第二个控制器中允许的方向。

看看这个tut:这很好地解释了如何在 ios 上制作启动画面。

于 2012-09-13T12:30:19.480 回答
0
  • 尝试呈现第二个视图而不是添加子视图,因为添加子视图不会调用 shouldAutorotateToInterfaceOrientation 方法。它肯定会解决你的问题。
于 2012-09-13T12:25:23.013 回答
0

尝试在该特定类的 viewDidLoad 中使用以下内容

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ;
于 2012-09-13T12:05:00.990 回答