Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何更改正在添加到窗口的工具栏的方向_Iphone_Ios_Objective C_Ipad - Fatal编程技术网

Iphone 如何更改正在添加到窗口的工具栏的方向

Iphone 如何更改正在添加到窗口的工具栏的方向,iphone,ios,objective-c,ipad,Iphone,Ios,Objective C,Ipad,我正在开发一个基于tabbarcontroller的应用程序。在一个视图控制器中,我想隐藏tabbarcontroller,而不是显示工具栏。为此,我编写了以下代码 //tabBAr hidden [self.tabBarController.tabBar setHidden:YES]; //creation of tool bar AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedAppli

我正在开发一个基于tabbarcontroller的应用程序。在一个视图控制器中,我想隐藏tabbarcontroller,而不是显示工具栏。为此,我编写了以下代码

    //tabBAr hidden
    [self.tabBarController.tabBar setHidden:YES];
    //creation of tool bar
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
     tb = [[UIToolbar alloc] init];
    //[tb setBackgroundImage:[UIImage imageNamed:@"tabbar.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    tb.tintColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
    {
        tb.frame = CGRectMake(0, delegate.window.frame.size.height-50, 320, 44);

    }
    else
    {
        tb.frame = CGRectMake(0, delegate.window.frame.size.height-70, 768, 44);
    }

    [delegate.window addSubview:tb];

但问题是在iPad中,我想更改工具栏的方向,但它不会更改。它始终采用纵向宽度和高度。

使用通知检测设备方向,如下所示

// Start Orientation //
- (void)orientationChanged:(NSNotification *)notification{
    [self adjustViewsForOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation) orientation {

    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        //NSLog(@"Vertical");

    }
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
    {
        //NSLog(@"Horizontal");

    }
}
// End Orientation //

-(void)viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification  object:nil];
}

有人在某处写了这个通知代码。我没有写它。

使用viewWillLayoutSubViews方法,并在该方法中向工具栏的setFrame添加代码

例:

- (void) viewWillLayoutSubviews
{
     [toolBar setFrmae:CGRectMake(self.view.bounds.origin.x, self.view.bounds.size.height - 44, self.view.bounds.size.width, 44)];
}