[英]Device Orientation in iphone sdk
i have a requirnmant for ipad to show contents both in landscape and portrait..so i have done the code and done the postions of controlles in each orientations.it works fine..my code is 我对ipad有要求,可以同时显示横向和纵向内容。.所以我已经完成了代码,并完成了各个方向上的控件位置。工作正常。.我的代码是
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
_viewContainer.frame = CGRectMake(342, 1, 681, 707);
_viewtopic.frame = CGRectMake(1, 62, 343, 56);
_viewpublicspeekingheaderleft.frame = CGRectMake(0, 6, 341, 58);
_viewTableview.frame = CGRectMake(1, 118, 341, 590);
_viewFooter.frame = CGRectMake(1, 716, 1024, 48);
if (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ) {
_viewContainer.frame = CGRectMake(276, 1, 503, 946);
_viewtopic.frame = CGRectMake(0, 58, 275, 50);
_viewpublicspeekingheaderleft.frame = CGRectMake(0, 1, 275, 58);
_viewTableview.frame = CGRectMake(1, 109, 274, 837);
_viewFooter.frame = CGRectMake(1, 954, 767, 48);
}
return YES;
}
the above code works fine for me,i got alla the controllers in corect postions..here is my probm,,i have to set a timer to show full screen and i need to hide some controlers in the viewcontroller,,i had done the timer set to 3 second and after 3 second it hides some controlles and arrange the othe controlers in the view controller to show the ful sceen.it also works fine for me.my code fo this is 上面的代码对我来说很好,我将所有控制器都放在了corect位置..这是我的问题,我必须设置一个计时器以显示全屏,并且我需要在viewcontroller中隐藏一些控制器,我已经完成了计时器设置为3秒,然后3秒后,它隐藏了一些控件并在视图控制器中安排了其他控件以显示ful sceen。它对我来说也很好。
- (void)viewDidLoad
{
[super viewDidLoad];
// Define the timer object
NSTimer *timer;
// Create the timer object
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self
selector:@selector(updateorientation:) userInfo:nil repeats:NO];
}
- (void) updateorientation:(NSTimer *)incomingTimer
{
_tableTopic.hidden =YES;
_viewtopic.hidden =YES;
_viewpublicspeekingheaderleft.hidden =YES;
_viewTableview.hidden =YES;
_imgpulbicspeakingabovethetableview.hidden =YES;
_topiclabel.hidden =YES;
_lblpublicspeekingleft.hidden =YES;
UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown ) {
NSLog(@"portrait");// only works after a rotation, not on loading app
_imgMicimage.frame = CGRectMake(69, 130, 635, 216);
_txtContentofTopic.frame = CGRectMake(69, 354, 635, 203);
_viewContainer.frame = CGRectMake(0, 0, 768, 1024);
}
UIInterfaceOrientation orientationLandscape =[[UIApplication sharedApplication] statusBarOrientation];
if (orientationLandscape == UIDeviceOrientationLandscapeLeft || orientationLandscape == UIDeviceOrientationLandscapeRight ) {
NSLog(@"landscape");
_imgMicimage.frame = CGRectMake(93, 113, 836, 239);
_txtContentofTopic.frame = CGRectMake(93, 360, 836, 203);
_viewContainer.frame = CGRectMake(0, 0, 1024, 768);
}
}
it works fine,but after the timer fires ,then i chnage the orientation of the device ,i only get the arrangmnts in the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
function.i need the arrangmnts in the time function.how to solve this. 它工作正常,但是在计时器触发后,然后我改变了设备的方向,我只在
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
应该AutorotateToInterfaceOrientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
function。解决这个。
thanks in advance. 提前致谢。
} }
You should not be doing this work in -shouldAutorotateToInterfaceOrientation:
. 您不应该在
-shouldAutorotateToInterfaceOrientation:
进行这项工作。 That method is simply to determine whether your UI should rotate (and will soon be superceded by a new system). 该方法只是确定您的UI是否应该旋转(不久将被新系统取代)。 You should use these methods to lay out your UI in reaction to an actual rotation:
您应该使用以下方法来布局UI以响应实际的轮换:
-willRotateToInterfaceOrientation:duration:
-willAnimateRotationToInterfaceOrientation:duration:
-didRotateFromInterfaceOrientation:
Please see the UIViewController
docs for more on those. 有关更多信息,请参阅
UIViewController
文档 。
On iOS 5, -viewWillLayoutSubviews
might be another good choice. 在iOS 5上,
-viewWillLayoutSubviews
可能是另一个不错的选择。 (It will be called even if your controller's view isn't currently visible.) (即使当前不显示控制器的视图,也会调用它。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.