Iphone CATTransferM3dMakeRotation似乎只在第二次正常工作
我正在使用以下相当基本的代码,因为我正在尝试学习如何为初学者使用基本的横向旋转进行转换 我想用很长的一段时间来学习更多的东西,而不仅仅是“应该自动旋转”的东西,这就是我现在正在编写的代码Iphone CATTransferM3dMakeRotation似乎只在第二次正常工作,iphone,ios,objective-c,xcode,ios-simulator,Iphone,Ios,Objective C,Xcode,Ios Simulator,我正在使用以下相当基本的代码,因为我正在尝试学习如何为初学者使用基本的横向旋转进行转换 我想用很长的一段时间来学习更多的东西,而不仅仅是“应该自动旋转”的东西,这就是我现在正在编写的代码 - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotificatio
- (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的帮助下自学:)
感谢您的帮助,祝您好运。如果您更改了肖像上的中心或边框,您应该将其更改回“风景”中。。。 此外,每次旋转滚动视图时,都应更改其内容大小 试试这样的
- (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) {
}];
}
}