0

我有一个用于启动画面的视图控制器,我已经处理了

A) 两个方向 -> 有两个 UIView,即 viewPortrait、viewLandscape

B) 两种屏幕尺寸 -> 3.5", 4"

我在 viewPortrait 上添加了 UIActivityIndi​​catorView 对象 spinner1 并在界面构建器中勾选了“动画”框。然后我在 viewLandscape 上添加了 UIActivityIndi​​catorView 对象 spinner2 并勾选了“动画”框。

这里的问题是,当我加载应用程序时,微调器没有动画。但是,当我旋转时,我可以看到微调器动画。我做错了什么?请看下面的代码。

界面:

#import <UIKit/UIKit.h>
#import "homeViewController.h"

@interface splashViewController : UIViewController

@property (nonatomic,retain) IBOutlet UIView *viewPortrait;
@property (nonatomic,retain) IBOutlet UIView *viewLandscape;
@property (nonatomic,retain) IBOutlet UIActivityIndicatorView *spinner1;
@property (nonatomic,retain) IBOutlet UIActivityIndicatorView *spinner2;
@property (nonatomic,retain) IBOutlet UIImageView *splash;

- (void) loadHomeView;
- (void) detectOrientation:(NSNotification *) obj;

@end

实现文件:

#import "splashViewController.h"

@implementation splashViewController
@synthesize splash,spinner1,spinner2,viewLandscape,viewPortrait;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {}
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(detectOrientation:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return YES;
}

- (void) detectOrientation: (NSNotification *) obj {
    CGSize result=[[UIScreen mainScreen] bounds].size;
    UIDeviceOrientation dev = [[obj object]orientation];
    if(dev == UIInterfaceOrientationPortrait || dev == UIInterfaceOrientationPortraitUpsideDown) {
        self.view = self.viewPortrait;
        self.splash.contentMode = UIViewContentModeScaleAspectFit;
        if(result.height==568) [self.spinner1 setCenter:CGPointMake(157.0,360.0)];
    }
    else {
        self.view = self.viewLandscape;
        if(result.height==568) {
            [self.spinner2 setCenter:CGPointMake(284.0,270.0)];
            self.splash.image = [UIImage imageNamed:@"Default-568.png"];
        }
    }
//    [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(loadHomeView) userInfo:nil repeats:NO];
}

- (void) loadHomeView {
    [self.spinner1 stopAnimating];
    [self.spinner2 stopAnimating];
    [self.spinner1 release];
    [self.spinner2 release];
    homeViewController *hv = [[[homeViewController alloc]initWithNibName:@"homeViewController" bundle:nil] autorelease];
    [self presentViewController:hv animated:NO completion:nil];
}

@end
4

0 回答 0