2013-11-28 60 views
1

目前在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); 
    } 
} 

任何幫助非常感激

回答

0

我認爲更好的地方來處理旋轉事件是viewDidLayoutSubviews方法,不通知中心。 我想補充一點這其中要居中它的每一個控制器:

​​
+0

是格雷格 - 這是目前我想此刻的做法,它的作品。但是當我從縱向旋轉到橫向時,它似乎並沒有重新設置活動指示器,因爲它爲上面的rootviewcontroller實施通知方法。 –

+0

- (void)viewDidLayoutSubviews { self.activityIndi​​cator.center = CGPointMake(self.view.bounds.size.width/2.0f,self.view.bounds.size.height/2.0f); }這個解決方案對我來說非常合適 –

0

試試這個:

self.activityIndicator.center = CGPointMake(self.view.bounds.size.width/2.0f, self.view.bounds.size.height/2.0f);// if you want whole screen center then used :[UIScreen mainScreen].bounds 

編碼快樂... :)

1

儘量給個人框架適用於縱向和橫向模式。

UIActivityIndicatorView *activityView; 

activityView = [[UIActivityIndicatorView alloc] init]; 

if(isPortraitMode) 
      [activityView setFrame:CGRectMake(147.5,227.5,25,25)]; 
     else 
      [activityView setFrame:CGRectMake(227.5,147.5,25,25)]; 

[self.view addSubview:activityView]; 
1

spinner.center = self.view.center;

0
- (void)viewDidLayoutSubviews {  
    self.activityIndicator.center = self.view.center; 
} 

試試這個人像