iOS: Device orientation on load

前端 未结 16 1953
遥遥无期
遥遥无期 2020-11-28 23:45

It seems that when my app loads, it does not know its current orientation:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (o         


        
16条回答
  •  难免孤独
    2020-11-29 00:08

    I still use this working code snippet for iphone 4:

    -(void)deviceOrientationDidChange:(NSNotification *)notification{
    
    //Obtaining the current device orientation
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];    
    
    int value = 0;
    
    if(orientation == UIDeviceOrientationPortrait)
    {
        value = 0;
    
    }else if(orientation == UIDeviceOrientationLandscapeLeft)
    {
        value = 90;
    
    }else if(orientation == UIDeviceOrientationLandscapeRight)
    {
    
        value = -90;
    
    }
    
    CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(value));
    [photoImageView setTransform:cgCTM];
    

    }

提交回复
热议问题