Rearrange object in table view for different orientation of iPad

前端 未结 1 1783
失恋的感觉
失恋的感觉 2021-01-28 04:31

I had a table populated with rows and each row contain image, title and a button.
When user change the orientation of the iPad button should be rearrange according to the or

相关标签:
1条回答
  • 2021-01-28 05:10

    This will work :

    -(void)viewWillAppear:(BOOL)animated
    {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
    }
    
    -(void)viewWillDisappear:(BOOL)animated
    {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    }  
    

    Now implement the following method :

    -(void)checkOrientation
    {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
        {
            [tblView reloadData];
            // Set x coorinate of views you want to change
    
        }
        else
        {
            [tblView reloadData];
            // Set x coordinates of views to initial x xoordinates.
    
        }
    
    }  
    

    Create recievedRotate :

    - (void)receivedRotate:(NSNotification *)notification
    {    
    [self checkOrientation];
    }  
    

    In viewDidLoad :

    -(void)viewDidLoad
    {  
    [self checkOrientation];
    }
    
    0 讨论(0)
提交回复
热议问题