目前在IOS 7下工作,使用下面的代碼我能夠在我的rootviewcontroller橫向和縱向活動指標居中。但是,通知不會在我的addviewcontroller或實際上我的detailviewcontroller爲同一個項目觸發。我希望能夠像我爲rootviewcontroller所做的那樣,將活動指示符集中在我的addviewcontroller和detailviewcontroller中。居中的活動指標肖像和風景Xcode
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
//Applications are expected to have root view controller at the end of application launch
self.window.rootViewController = navigationController;
return YES;
}
下面的代碼演示瞭如何我在viewDidLoad中
//Setup Activity Indicator.
self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
self.activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.activityIndicator.transform = CGAffineTransformMakeScale(1.35, 1.35);
[self.view addSubview:self.activityIndicator];
設置我的活動指示燈在我的RootViewController的,addviewcontroller和detailviewcontroller下面的代碼是什麼,我用它來中心活動指示燈我稱之爲在我的rootviewcontroller的ViewDidLoad中。
//Make sure the activity indicator is centered both in landscape and portrait
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
-(void)didRotate:(NSNotification *)notification {
if (activityIndicator) {
activityIndicator.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
}
}
任何幫助非常感激
是格雷格 - 這是目前我想此刻的做法,它的作品。但是當我從縱向旋轉到橫向時,它似乎並沒有重新設置活動指示器,因爲它爲上面的rootviewcontroller實施通知方法。 –
- (void)viewDidLayoutSubviews { self.activityIndicator.center = CGPointMake(self.view.bounds.size.width/2.0f,self.view.bounds.size.height/2.0f); }這個解決方案對我來說非常合適 –