【发布时间】:2013-11-28 09:19:13
【问题描述】:
目前在 IOS 7 下工作,使用下面的代码,我能够在我的 rootviewcontroller 中将活动指示器置于横向和纵向的中心。但是,该通知不会在我的 addviewcontroller 或我的同一项目的 detailviewcontroller 中触发。我希望能够在我的 addviewcontroller 和 detailviewcontroller 中将活动指示器居中,就像我为 rootviewcontroller 所做的那样。
- (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;
}
以下代码说明了我如何在我的 rootviewcontroller 中设置我的 Activity Indicator,在 ViewdidLoad 中添加viewcontroller 和 detailviewcontroller
//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];
下面的代码是我用来在我的根视图控制器的 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);
}
}
非常感谢任何帮助
【问题讨论】:
标签: iphone objective-c ios7 xcode5