0
votes

I want to rotate my UISlider in iPhone landscape layouts and am using this code to to it.

self.customSlider.transform = CGAffineTransformMakeRotation(M_PI/2);

However, I want to use it in -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator so that it rotates appropriately based on size classes.

I have the following code where I put other rotation code

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {

[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
    self.stillCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight;

}

if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
    self.stillCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;

}

if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
    self.stillCamera.outputImageOrientation = UIDeviceOrientationPortrait;
}

}

I want to make sure that the UISlider is in the proper orientation in each orientation with the left edge of the slider on top in landscape and the right on the bottom. I need to check the rotation to make sure that slider is in the right position regardless of how the user rotates from portrait to landscape left or right. How can I do this?

EDIT: I am using GPUImage and the preview view uses an orientation left/right for that view, so I need to find an implementation that allows me to keep that while also allowing for general size class customization.

1
How many orientations your app supports??Leena
portrait and landscape using regular and compact/compact. I might use the weird Trait Collection for the 6+ but so far it looks fine just using compact/compact.noobsmcgoobs

1 Answers

0
votes

I figured it out

First - place the UISlider in a container view and pin that container view as needed.

Pin the UISlider to the container view in portrait - either centered horizontally/vertically with equal height/width to container.

In landscape, pin container view as needed with UISlider centered H/V with equal width to container.

In

-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {


    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
        self.stillCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight;
         self.customSlider.transform = CGAffineTransformMakeRotation(M_PI/2);

    }

    if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeRight) {
        self.stillCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
         self.customSlider.transform = CGAffineTransformMakeRotation(M_PI/2);

    }

    if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
        self.stillCamera.outputImageOrientation = UIDeviceOrientationPortrait;
        self.customSlider.transform = CGAffineTransformIdentity;
    }

}