![](/img/trans.png)
[英]How to rotate orientation of UIImage when application have only one orientation
[英]how to make uiviews only rotate (transform) when orientation changes?
我正在寻求实现类似于ios相机应用程序的行为。 更改方向后,视图和控件仅在原地旋转,而保持不变。 我试图设置这样的位置
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect newBottomControlsFrame;
CGRect newTopControlsFrame;
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
CGFloat screenHeight = fmaxf(self.view.bounds.size.height, self.view.bounds.size.width);
newBottomControlsFrame.origin.x = 0;
newBottomControlsFrame.origin.y = screenHeight - 70;
newBottomControlsFrame.size.height = 70;
newBottomControlsFrame.size.width = 320;
newTopControlsFrame.origin = CGPointMake(0, 0);
newTopControlsFrame.size = CGSizeMake(320, 50);
self.bottomControlsContainer.frame = newBottomControlsFrame;
self.topControlsContainer.frame = newTopControlsFrame;
NSLog(@"Frame: %f, %f, %f, %f", newBottomControlsFrame.origin.x,newBottomControlsFrame.origin.y,
newBottomControlsFrame.size.width,newBottomControlsFrame.size.height);
} else {
CGFloat screenHeight = fmaxf(self.view.bounds.size.height, self.view.bounds.size.width);
newBottomControlsFrame.origin.x = screenHeight - 70;
newBottomControlsFrame.origin.y = 0;
newBottomControlsFrame.size.height = 320;
newBottomControlsFrame.size.width = 70;
newTopControlsFrame.origin = CGPointMake(0, 0);
newTopControlsFrame.size = CGSizeMake(50, 320);
self.bottomControlsContainer.frame = newBottomControlsFrame;
self.topControlsContainer.frame = newTopControlsFrame;
NSLog(@"Frame: %f, %f, %f, %f", newBottomControlsFrame.origin.x,newBottomControlsFrame.origin.y,
newBottomControlsFrame.size.width,newBottomControlsFrame.size.height);
}
}
该解决方案的问题是视图将其动画方式设置为“新”位置,而不是保持其位置并且仅进行变换。
感谢您的时间! :)
我找到了解决方案。 为了实现这一行为,应在以下位置设置视图的“新”位置
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[UIView setAnimationsEnabled:NO];
// set the new positions ...
}
然后,在
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[UIView setAnimationsEnabled:YES];
// make a transform animation manually
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.