how to set orientation for a view which is subviewed to window

前端 未结 1 408
执念已碎
执念已碎 2021-01-17 02:40

\"enter

I have created a UIView.I want to subview the view to the appdelegate wind

相关标签:
1条回答
  • 2021-01-17 03:29

    if we add any object to window and then we want to change the orientation then we must use transform methods.

    #define DegreesToRadians(degrees) (degrees *M_PI /180)
    

    add above line

    CGAffineTransform newTransform;
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    switch (orientation)
    {
        case UIInterfaceOrientationPortraitUpsideDown:
            newTransform = CGAffineTransformMakeRotation(-DegreesToRadians(180));
            txt.transform = newTransform;
            txt.frame = CGRectMake(0, 0, 320, 480);
                    break;
        case UIInterfaceOrientationLandscapeLeft:
            newTransform = CGAffineTransformMakeRotation(DegreesToRadians(-90));
            txt.transform = newTransform;
            txt.frame = CGRectMake(0, 0, 320, 480);
    
            break;
        case UIInterfaceOrientationLandscapeRight:
            newTransform = CGAffineTransformMakeRotation(DegreesToRadians(90));
            txt.transform = newTransform;
            txt.frame = CGRectMake(0, 0, 320, 480);
    
    
            break;
        default: 
            newTransform = CGAffineTransformMakeRotation(-DegreesToRadians(0));
            txt.transform = newTransform;
            txt.frame = CGRectMake(0, 0, 320, 480);
    
            break;                             
    }    
    

    here txt is object name,try in this way.

    0 讨论(0)
提交回复
热议问题