带导航后退按钮的自动旋转
我正在创建一个支持所有方向的应用程序。
我在这里使用 navigationController。
对于方向,我正在使用此代码,
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
category1.frame = CGRectMake(54, 68, 190, 174);
category2.frame = CGRectMake(291, 68, 190, 174);
category3.frame = CGRectMake(525, 68, 190, 174);
category4.frame = CGRectMake(54, 296, 190, 174);
category5.frame = CGRectMake(291, 296, 190, 174);
category6.frame = CGRectMake(525, 296, 190, 174);
category7.frame = CGRectMake(54, 527, 190, 174);
category8.frame = CGRectMake(291, 527, 190, 174);
category9.frame = CGRectMake(525, 527, 190, 174);
category10.frame = CGRectMake(291, 757, 190, 174);
extra1.frame = CGRectMake(80, 781, 138, 125);
extra2.frame = CGRectMake(551, 781, 138, 125);
}
else
{
category1.frame = CGRectMake(61, 50, 190, 174);
category2.frame = CGRectMake(298, 50, 190, 174);
category3.frame = CGRectMake(537, 50, 190, 174);
category4.frame = CGRectMake(774, 50, 190, 174);
category5.frame = CGRectMake(61, 278, 190, 174);
category6.frame = CGRectMake(298, 278, 190, 174);
category7.frame = CGRectMake(537, 278, 190, 174);
category8.frame = CGRectMake(774, 278, 190, 174);
category9.frame = CGRectMake(298, 509, 190, 174);
category10.frame = CGRectMake(537, 509, 190, 174);
extra1.frame = CGRectMake(80, 533, 120, 125);
extra2.frame = CGRectMake(800, 533, 120, 125);
}
}
它在此视图中完美运行。当我选项卡按钮时,它会转到第二个视图控制器,我在其中显示表格视图。
但是,如果我通过导航后退按钮返回第一个视图,方向不会完美显示。
上面的代码不适用于导航后退按钮。
对于这个问题我该怎么办?
有什么建议吗?
先感谢您。
编辑:
我已从firstview 中删除了上述函数,并将代码复制到该函数中。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
category1.frame = CGRectMake(54, 68, 190, 174);
category2.frame = CGRectMake(291, 68, 190, 174);
category3.frame = CGRectMake(525, 68, 190, 174);
category4.frame = CGRectMake(54, 296, 190, 174);
category5.frame = CGRectMake(291, 296, 190, 174);
category6.frame = CGRectMake(525, 296, 190, 174);
category7.frame = CGRectMake(54, 527, 190, 174);
category8.frame = CGRectMake(291, 527, 190, 174);
category9.frame = CGRectMake(525, 527, 190, 174);
category10.frame = CGRectMake(291, 757, 190, 174);
extra1.frame = CGRectMake(80, 781, 138, 125);
extra2.frame = CGRectMake(551, 781, 138, 125);
}
else
{
category1.frame = CGRectMake(61, 50, 190, 174);
category2.frame = CGRectMake(298, 50, 190, 174);
category3.frame = CGRectMake(537, 50, 190, 174);
category4.frame = CGRectMake(774, 50, 190, 174);
category5.frame = CGRectMake(61, 278, 190, 174);
category6.frame = CGRectMake(298, 278, 190, 174);
category7.frame = CGRectMake(537, 278, 190, 174);
category8.frame = CGRectMake(774, 278, 190, 174);
category9.frame = CGRectMake(298, 509, 190, 174);
category10.frame = CGRectMake(537, 509, 190, 174);
extra1.frame = CGRectMake(80, 533, 120, 125);
extra2.frame = CGRectMake(800, 533, 120, 125);
}
return YES;
}
在我的第二个视图控制器中,我已经完成了
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
当我通过点击导航后退按钮返回第一个视图时其他条件(横向模式)工作正常,但我不知道为什么它不能与一起使用if 条件(肖像模式)。
I am creating an app which support all orientation.
I am using navigationController here.
for orientation i am using this code
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
category1.frame = CGRectMake(54, 68, 190, 174);
category2.frame = CGRectMake(291, 68, 190, 174);
category3.frame = CGRectMake(525, 68, 190, 174);
category4.frame = CGRectMake(54, 296, 190, 174);
category5.frame = CGRectMake(291, 296, 190, 174);
category6.frame = CGRectMake(525, 296, 190, 174);
category7.frame = CGRectMake(54, 527, 190, 174);
category8.frame = CGRectMake(291, 527, 190, 174);
category9.frame = CGRectMake(525, 527, 190, 174);
category10.frame = CGRectMake(291, 757, 190, 174);
extra1.frame = CGRectMake(80, 781, 138, 125);
extra2.frame = CGRectMake(551, 781, 138, 125);
}
else
{
category1.frame = CGRectMake(61, 50, 190, 174);
category2.frame = CGRectMake(298, 50, 190, 174);
category3.frame = CGRectMake(537, 50, 190, 174);
category4.frame = CGRectMake(774, 50, 190, 174);
category5.frame = CGRectMake(61, 278, 190, 174);
category6.frame = CGRectMake(298, 278, 190, 174);
category7.frame = CGRectMake(537, 278, 190, 174);
category8.frame = CGRectMake(774, 278, 190, 174);
category9.frame = CGRectMake(298, 509, 190, 174);
category10.frame = CGRectMake(537, 509, 190, 174);
extra1.frame = CGRectMake(80, 533, 120, 125);
extra2.frame = CGRectMake(800, 533, 120, 125);
}
}
It works perfectly in this view. when i tab button it goes to secondviewcontroller where i am showing tableview.
But , if i go back to the firstview via navigation back button ,the orientation is not showing perfectly.
Above code is not working for navigation back button.
What should i do for this problem??
Any suggestion ??
Thank you in advance.
Edited:
I have removed my above function from firstview and copy the code to this function.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
category1.frame = CGRectMake(54, 68, 190, 174);
category2.frame = CGRectMake(291, 68, 190, 174);
category3.frame = CGRectMake(525, 68, 190, 174);
category4.frame = CGRectMake(54, 296, 190, 174);
category5.frame = CGRectMake(291, 296, 190, 174);
category6.frame = CGRectMake(525, 296, 190, 174);
category7.frame = CGRectMake(54, 527, 190, 174);
category8.frame = CGRectMake(291, 527, 190, 174);
category9.frame = CGRectMake(525, 527, 190, 174);
category10.frame = CGRectMake(291, 757, 190, 174);
extra1.frame = CGRectMake(80, 781, 138, 125);
extra2.frame = CGRectMake(551, 781, 138, 125);
}
else
{
category1.frame = CGRectMake(61, 50, 190, 174);
category2.frame = CGRectMake(298, 50, 190, 174);
category3.frame = CGRectMake(537, 50, 190, 174);
category4.frame = CGRectMake(774, 50, 190, 174);
category5.frame = CGRectMake(61, 278, 190, 174);
category6.frame = CGRectMake(298, 278, 190, 174);
category7.frame = CGRectMake(537, 278, 190, 174);
category8.frame = CGRectMake(774, 278, 190, 174);
category9.frame = CGRectMake(298, 509, 190, 174);
category10.frame = CGRectMake(537, 509, 190, 174);
extra1.frame = CGRectMake(80, 533, 120, 125);
extra2.frame = CGRectMake(800, 533, 120, 125);
}
return YES;
}
in my second view controller i have done
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
When i go back to the firstview by tapping navigation back button else condition(landscape mode) works fine but i don't know why it is not working with if condition(Portraitmode).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将所有这些代码写入以下函数中。
新编辑:
将此方法写入您的detailviewcontroller.m 文件中
Write all this code in the following function.
NEW EDIT :
Write this method into your detailviewcontroller.m file