旋转全屏 UIImageView
我有两个图像:
Help-Portrait.png (320 x 480)
Help-Landscape.png (480 x 320)
当用户单击任何视图上的帮助按钮时,需要向他们显示正确的图像,并且该图像也应该随着设备的旋转而旋转。我尝试将 imageView 添加到窗口和导航控制器视图中。
由于某种原因,我对此有疑问。 有人能阐明我做错了什么吗?
UIImage *image = nil;
CGRect frame;
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
image = [UIImage imageNamed:@"Help-Portrait.png"];
frame = CGRectMake(0, 0, 320, 480);
} else {
image = [UIImage imageNamed:@"Help-Landscape.png"];
frame = CGRectMake(0, 0, 480, 320);
}
if (!helpImageView) {
helpImageView = [[UIImageView alloc] initWithFrame:frame];
helpImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
helpImageView.image = image;
}
[[UIApplication sharedApplication] setStatusBarHidden:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(helpImageTapped:)];
helpImageView.userInteractionEnabled = YES;
[helpImageView addGestureRecognizer:tap];
[self.view addSubview:helpImageView];
[tap release];
willRotateToInterfaceOrientation:
if(helpImageView) {
[(id)[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
helpImageView.image = [UIImage imageNamed:@"Help-Portrait.png"];
} else {
helpImageView.image = [UIImage imageNamed:@"Help-Landscape.png"];
}
}
当您旋转设备时,图像和框架不会改变,最终会在屏幕左侧显示三分之二的肖像图像。
我想要的是它能够显示方向正确的图像,即正确的向上方向。我也想要图像旋转的动画,但这是一个附带问题
I have two images:
Help-Portrait.png (320 x 480)
Help-Landscape.png (480 x 320)
When a user clicks the help button on any view, they need to be presented with the correct image, which should also rotate when the device does. I have tried adding the imageView to both the window, and the navigation controller view.
For some reason I am having issues with this.
Could anyone shed light on what I am doing wrong?
UIImage *image = nil;
CGRect frame;
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
image = [UIImage imageNamed:@"Help-Portrait.png"];
frame = CGRectMake(0, 0, 320, 480);
} else {
image = [UIImage imageNamed:@"Help-Landscape.png"];
frame = CGRectMake(0, 0, 480, 320);
}
if (!helpImageView) {
helpImageView = [[UIImageView alloc] initWithFrame:frame];
helpImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
helpImageView.image = image;
}
[[UIApplication sharedApplication] setStatusBarHidden:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(helpImageTapped:)];
helpImageView.userInteractionEnabled = YES;
[helpImageView addGestureRecognizer:tap];
[self.view addSubview:helpImageView];
[tap release];
willRotateToInterfaceOrientation:
if(helpImageView) {
[(id)[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
helpImageView.image = [UIImage imageNamed:@"Help-Portrait.png"];
} else {
helpImageView.image = [UIImage imageNamed:@"Help-Landscape.png"];
}
}
When you rotate the device the image and the frame don't change, and you end up with two thirds of the portrait image displayed on the left part of the screen.
What I want is it for it to show the correct image for the orientation, the right way up. Also I would like animation for the image rotation, but thats a side issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要调整按钮图像的位置位于 ViewController 的
shouldAutorotateToInterfaceOrientation
方法(为您链接的文档)。做类似的事情:
The place where you need to adjust your button image is in your ViewController's
shouldAutorotateToInterfaceOrientation
method (documentation linked for you).Do something like:
Michael Dautermann 的答案看起来几乎包含了所有答案,但我反对使用shouldAutorotateToInterfaceOrientation。此方法的设计目的只是为了确定是否应该发生旋转,仅用于确定是否应该发生旋转。
您应该使用
didRotateFromInterfaceOrientation:
willAnimateRotationToInterfaceOrientation:duration
来代替。didRotateFromInterfaceOrientation:
-interfaceOrientation
已在您的UIViewController
上设置,因此您可以获得当前方向。在这种情况下,旋转动画已经完成。willAnimateRotationToInterfaceOrientation:duration
- 此方法的好处是执行时间。您处于旋转动画内部,因此在旋转动画完成后更改 UI 时不会出现不太漂亮的效果。Michael Dautermann's answer looks to have almost all the answer, but I'm opposed to using
shouldAutorotateToInterfaceOrientation
. This method is designed only to determine if a rotation should or should not occur, nothing else.You should use either
didRotateFromInterfaceOrientation:
willAnimateRotationToInterfaceOrientation:duration
instead.didRotateFromInterfaceOrientation:
-interfaceOrientation
is already set on yourUIViewController
so you can get the current orientation. In this case the rotation animation is already complete.willAnimateRotationToInterfaceOrientation:duration
- The benefit of this method is execution time. You are inside the rotation animation so you won't have the less than pretty effects which happens when you change UI either after the rotation animation completes.使用这段代码让它工作:
得到这个想法:
http:// www.dobervich.com/2010/10/22/fade-out-default-ipad-app-image-with-proper-orientation/
Got it working, with this code:
Got the idea from:
http://www.dobervich.com/2010/10/22/fade-out-default-ipad-app-image-with-proper-orientation/