如何检查appdelegate上的横向和纵向模式?
我想在横向和纵向模式下运行应用程序,如何检查appdelegate上的横向和纵向模式?
如何在Appdelegate上检查横向和纵向模式?
我打电话
- (BOOL) isPad{
#ifdef UI_USER_INTERFACE_IDIOM
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
#else
return NO;
#endif
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([self isPad]) {
NSLog(@"is pad method call");
return YES;
}
else
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
}
- (BOOL)isPadPortrait
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationPortrait
|| self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
- (BOOL)isPadLandscape
{
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
&& (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));
}
,但给出了类型的appdelegate的对象未找到错误 接口属性定位。
我该怎么做?
你应该检查你的iPad使用的当前方向。我建议你在每个视图上检查这些条件,并根据当前的方向采取行动:
if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
{
//Do what you want in Landscape Left
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
{
//Do what you want in Landscape Right
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait)
{
//Do what you want in Portrait
}
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do what you want in Portrait Upside Down
}
我希望这可以帮助你。 :)
如果您需要任何帮助,请随时与我联系。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
NSString *nibName = UIDeviceOrientationIsLandscape(orientation) ? @"Landscape" : @"Portrait";
NSLog(@"orientation is %@",nibName);
}
我已经创建了一个方法 - 上的appdelegate showplayer中,我尝试检查横向和纵向的方法,和所有其他网页上的我叫-showplayer方法,按照乌拉圭回合的建议,我觉得不能够给予笔尖每个其他页面的名称,是否有任何其他方式来检查土地景观肖像? –
如果铺设单位,设备方向可能会有问题,您应该改用状态bas orientation我认为 – NightCoder
委托方向是,我们在plist中指定,如果我们不是在plist中方向其指定将采取纵向模式默认。但在委托你只有不适用的重要窗口方向支持你必须添加视图控制器或任何导航控制器的视图,然后你可以调用这些功能,他们会给你的设备的正确方向。
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight)
{
NSLog(@"Lanscapse");
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{
NSLog(@"UIDeviceOrientationPortrait");
}
}
@Ankit:这对您有帮助吗? –
这不适用于appDelegate。在我的情况下,无论方向如何,条件始终是LandscapeRight。 – NightCoder