我正在使用以下非常基本的代码,因为我正在尝试学习如何为初学者进行基本横向旋转的转换
我想做的远远不仅仅是投入'shouldautorotate'的东西,这就是我现在正在处理的代码
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeRight)
{
[UIView animateWithDuration:0.2f animations:^{
self.view.layer.transform = CATransform3DMakeRotation(-M_PI/2, 0, 0.0, 1.0);
[self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)];
[self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES];
} completion:^(BOOL finished) {
}];
} else if(orientation == UIDeviceOrientationPortrait) {
[UIView animateWithDuration:0.2f animations:^{
self.view.frame = CGRectMake(0, 0, 320.0, 480.0);
self.view.center = CGPointMake(160.0, 240.0);
self.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
}
}
然而,当我第一次从肖像旋转时,我得到了这个
但是一旦我将它恢复为肖像并再次旋转,我就会接受
如果这是一个愚蠢的问题,或者我遗漏了一些明显的问题,我真的很抱歉。我在SO的帮助下一般都在学习:)感谢您的帮助,请有一个好人。
答案 0 :(得分:0)
如果您更改了Portrait上的中心或框架,则应将其更改回Landscape ... 你也应该在每次旋转时更改滚动视图的contentSize。
尝试这样的事情......
- (void)didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeRight)
{
[UIView animateWithDuration:0.2f animations:^{
self.view.frame = CGRectMake(0, 0, 480.0, 320.0);
self.view.center = CGPointMake(240.0, 160.0);
self.view.layer.transform = CATransform3DMakeRotation(-M_PI/2, 0, 0.0, 1.0);
[self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)];
[self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES];
} completion:^(BOOL finished) {
}];
} else if(orientation == UIDeviceOrientationPortrait) {
[UIView animateWithDuration:0.2f animations:^{
self.view.frame = CGRectMake(0, 0, 320.0, 480.0);
self.view.center = CGPointMake(160.0, 240.0);
self.view.transform = CGAffineTransformIdentity;
[self.scrollViewImages setContentSize:CGSizeMake(self.view.frame.size.width*self.images.count, 320.0)];
[self.scrollViewImages setContentOffset:CGPointMake(0, 0) animated:YES];
} completion:^(BOOL finished) {
}];
}
}