【问题标题】:CGAffineTransformMakeRotation to rotate UISlider in viewWillTransitionToSizeCGAffineTransformMakeRotation 在 vi​​ewWillTransitionToSize 中旋转 UISlider
【发布时间】:2015-10-17 08:02:45
【问题描述】:

我想在 iPhone 横向布局中旋转我的 UISlider,并使用此代码。

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

但是,我想在-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator 中使用它,以便它根据尺寸等级适当地旋转。

我在下面的代码中放置了其他轮换代码

-(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;
}

}

我想确保 UISlider 在每个方向上都处于正确的方向,滑块的左边缘在横向顶部,右侧在底部。无论用户如何从纵向向左或向右旋转,我都需要检查旋转以确保滑块处于正确的位置。我该怎么做?

编辑: 我正在使用 GPUImage 并且预览视图使用该视图的左/右方向,因此我需要找到一个实现,让我可以保留它,同时还允许通用尺寸类自定义。

【问题讨论】:

  • 你的应用支持多少方向??
  • 纵向和横向使用常规和紧凑/紧凑。我可能会为 6+ 使用奇怪的特征集合,但到目前为止,使用紧凑/紧凑看起来还不错。

标签: ios rotation cgaffinetransform viewwilltransitiontosize


【解决方案1】:

我想通了

首先 - 将 UISlider 放置在容器视图中,并根据需要固定该容器视图。

将 UISlider 固定到纵向的容器视图 - 水平/垂直居中,高度/宽度与容器相等。

在横向中,根据需要使用 UISlider 居中的 H/V 固定容器视图,宽度与容器相等。

-(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;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多