【问题标题】:Iphone Splash Screen challenge with Orientation带方向的 Iphone 闪屏挑战
【发布时间】:2012-09-13 11:54:10
【问题描述】:

在 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 图像在初始视图上,但初始视图仍然出现在视图的背面..我只有模拟器来测试..有人可以帮我解决这个问题吗??

【问题讨论】:

  • 15 秒启动画面?我肯定不会使用你的应用程序。
  • 最多只能持续 3 秒.. 这只是一个示例代码而不是实际代码.. lolz
  • 如果您在启动画面中处于横向模式,您可能希望您的第二个视图在横向但允许它以纵向旋转不?

标签: iphone objective-c xcode


【解决方案1】:

您不应该在您的 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 上制作启动画面。

【讨论】:

    【解决方案2】:

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

     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] ;
    

    【讨论】:

      【解决方案3】:

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

      -(void)switchView
      {
       [ani stopAnimating];
       SecondView *sec=[[SecondView alloc]init];
      
      AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
      
      appDelegate.window.rootViewController = sec;
      
      }
      

      【讨论】:

        【解决方案4】:
        • 尝试呈现第二个视图而不是添加子视图,因为添加子视图不会调用 shouldAutorotateToInterfaceOrientation 方法。一定能解决你的问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-05-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多