Iphone 标签在横向模式下未正确对齐

Iphone 标签在横向模式下未正确对齐,iphone,ios,ipad,orientation,coordinates,Iphone,Ios,Ipad,Orientation,Coordinates,下面的代码正确吗?当用户旋转设备时,两个标签应指向下面给出的坐标。当用户在纵向模式下启动应用程序时,它会工作,标签放置正确。但是,当用户以横向模式启动时,标签无法正确放置。但如果将视图旋转为纵向,然后再旋转回横向,则它们会正确对齐。我试着在viewDidLoad中放置横向坐标,但仍然不起作用。我该怎么办?谢谢你的帮助 这两个标签是recordingTimeLabel和recordingTimeLabelMinutes - (void)willRotateToInterfaceOrientatio

下面的代码正确吗?当用户旋转设备时,两个标签应指向下面给出的坐标。当用户在纵向模式下启动应用程序时,它会工作,标签放置正确。但是,当用户以横向模式启动时,标签无法正确放置。但如果将视图旋转为纵向,然后再旋转回横向,则它们会正确对齐。我试着在viewDidLoad中放置横向坐标,但仍然不起作用。我该怎么办?谢谢你的帮助

这两个标签是recordingTimeLabel和recordingTimeLabelMinutes

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

 if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
     //is landscape

     backGround.frame = CGRectMake(0, 0, 768, 1024);

     recordingTimeLabel.center = CGPointMake(967, 22);
     recordingTimeLabelMinutes.center = CGPointMake(901, 22);

     NSLog(@"is landscape");

     //  fixedSpace.width = 400;

 } else {
     //is portrait

     backGround.frame = CGRectMake(0, 0, 1024, 768);

     recordingTimeLabel.center = CGPointMake(710, 22);
     recordingTimeLabelMinutes.center = CGPointMake(661, 22);

     NSLog(@"is portrait");

 }



}
此外,此代码也不起作用:

-(void)viewWillAppear:(BOOL)animated {        
if (([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)) {
    //is landscape

    backGround.frame = CGRectMake(0, 0, 768, 1024);

    recordingTimeLabel.center = CGPointMake(967, 22);
    recordingTimeLabelMinutes.center = CGPointMake(901, 22);

    NSLog(@"is landscape");

} else {
    //is portrait

    backGround.frame = CGRectMake(0, 0, 1024, 768);

    recordingTimeLabel.center = CGPointMake(710, 22);
    recordingTimeLabelMinutes.center = CGPointMake(661, 22);

    NSLog(@"is portrait");

}

}

willRotateToInterfaceOrientation:
如果以横向模式启动,则可能不会调用。我建议在
视图中设置坐标将显示:
,而不是
viewDidLoad
,以确定初始方向(如果启用了自动旋转,则可以使用
self.interface-orientation

是否也为UIInterfaceOrientation设置了以下代码

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

明白了。我经常使用NSTimer并调用包含以下代码的函数:

-(void)updateLabelLocation {

    if (([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)) {

    recordingTimeLabel.center = CGPointMake(710, 22);
    recordingTimeLabelMinutes.center = CGPointMake(661, 22);

    } 

}

顺便说一句,在日志中,首先打印is横向,然后紧接着打印is纵向,即使设备从未旋转过。此外,背景的大小和位置正确。is
视图将显示:
被调用两次?我这样做了,但它不起作用。这是我的代码:-(void)视图将出现:(BOOL)动画{if([[UIDevice currentDevice]方向]==UIInterfaceOrientationAndscapeRight)|([[UIDevice currentDevice]方向]==UIInterfaceOrientationAndscapeLeft)){//是横向记录TimeLabel.center=CGPointMake(967,22);recordingTimeLabelMinutes.center=CGPointMake(901,22);NSLog(@“is-landscape”);}否则{}我取出了else以节省空间,但这是正确的。“没有工作”?它有什么作用吗?请在问题中编辑该代码。是的,请输入。没有,没有结果。同样,在日志中,“是横向的”后面会显示一个“是纵向的”,即使设备只是横向的。是的,它会在所有四个方向上旋转。准确地说,并将调用viewWillAppear.NSTimer中方法的代码放入?对不起,这是一个可怕的解决方案。这是我唯一能用的方法。我也可以在延迟0后调用该函数,因为这不涉及NSTimer。