[英]CGAffineTransformMakeRotation to rotate UISlider in viewWillTransitionToSize
我想在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,並且預覽視圖對該視圖使用左/右方向,因此,我需要找到一個實現方式,使我可以保留該方向,同時還允許自定義尺寸類。
我想到了
首先-將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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.