Iphone 如何在通过appdelegate窗口添加时使viewcontroller旋转

Iphone 如何在通过appdelegate窗口添加时使viewcontroller旋转,iphone,objective-c,ios,xcode,ipad,Iphone,Objective C,Ios,Xcode,Ipad,我在appdelegate类的窗口中添加了一个viewcontroller,如下所示: -(void)showSearchView:(BOOL)view { if(view) { searchViewController = [[SearchView alloc] initWithNibName:@"SearchView" bundle:nil]; CGRect viewFrame=searchViewController.view.frame;

我在appdelegate类的窗口中添加了一个viewcontroller,如下所示:

-(void)showSearchView:(BOOL)view
{
    if(view)
    {
        searchViewController = [[SearchView alloc] initWithNibName:@"SearchView" bundle:nil];
        CGRect viewFrame=searchViewController.view.frame;
        viewFrame.origin.y=-1024;
        viewFrame.origin.x=248;
        [window addSubview:searchViewController.view];
        searchViewController.view.frame = viewFrame;
        [UIView beginAnimations:@"UIBase Hidden" context:nil];
        [UIView setAnimationDuration:0.5]; 
        searchViewController.view.transform = CGAffineTransformMakeTranslation(0,1024);

        [UIView commitAnimations];
    }
    else 
    {
        [UIView beginAnimations:@"UIBase Shown" context:nil];
        [UIView setAnimationDuration:0.5];
        searchViewController.view.transform = CGAffineTransformIdentity;
        [UIView commitAnimations];
        [self performSelector:@selector(doTHis) withObject:nil afterDelay:1];

    }

} 
通过此命令从其他类调用它 [apd showSearchView:是]; 其中apd是appdelegate类的对象

在这里之前一切都很好,但当我尝试旋转时,它不会旋转。我甚至在以下方法中返回“是”,但它仍然不旋转:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{   
    return YES;
}

应该怎么做?

请记住UIWindow不会旋转。也许您应该添加一个基本视图控制器并进行旋转

谢谢你的回答。但我怎样才能在其中添加一个基本视图控制器呢?我的意思是在窗口中添加一个视图控制器。在基本视图控制器中添加showsearchview方法。嘿,谢谢,我将-voidshowSearchView:BOOLview修改为-voidshowSearchView:BOOLview fromView:UIView*mainView,然后更改了[window addSubview:searchViewController.view];到[mainView addSubview:searchViewController.view];现在每件事都很完美。非常感谢,否则我早就不知道了@SahilTyagi很高兴能提供一些帮助: