2011-05-09 34 views

回答

12

尝试设置你的活动视图的center财产,像这样:

activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2); 

viewDidLoad,注册通知的设备旋转:

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

和实施didRotate:

-(void)didRotate:(NSNotification *)notification { 
    if (activity) { 
    activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2); 
    } 
} 
+0

当我旋转屏幕时它仍然会居中吗?谢谢 – Tim 2011-05-09 02:07:29

+0

不,你一旦注册它就必须重新居中。所以基本上只是在收到轮换通知时重新居中。欢迎来到Stack Overflow。 :) – 2011-05-09 02:09:30

+0

如何以及在哪里让它重新居中?我开始喜欢这个地方 – Tim 2011-05-09 02:17:44