2013-05-02 73 views

回答

0

首先你應該抓住定位:

//AppDelegate.h 
@interface AppDelegate : UIResponder <UIApplicationDelegate> 
@property (nonatomic, unsafe_unretained) NSInteger isPortrait; 

//AppDelegate.m 
@synthesize isPortrait; 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    isPortrait = 1; 

} 

執行狀態:後旋轉爲橫向模式顯示正確的寬度和回波泰特寬度後

-(void)viewWillAppear:(BOOL)animated{ 

    [[UIApplication sharedApplication] statusBarOrientation]; 
    [[UIDevice currentDevice] orientation]; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

//methode deviceRotated 

-(void)deviceRotated:(NSNotification*)notification{ 

    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    { 
     [self searchBarLandscape]; 
     app.isPortrait = NO; 
    } 
    else{ 
    [self searchBarPortrait]; 
    app.isPortrait = YES; 
    } 

} 

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

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || toInterfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
    app.isPortrait = 1; 
    } 
    else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
    app.isPortrait = 0; 
    } 
    [self prepareSearchBarOrientation]; 

} 


-(void)prepareSearchBarOrientation 
{ 

    AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    if (app.isPortrait) 
    { 
     [self searchBarPortrait];//Set Frame here 
    } 
    else 
    { 
     [self searchBarLandscape]; 

    } 

} 
+0

當從風景旋轉到縱向時,請讓我看看問題的圖像。 – Sovannarith 2013-05-02 06:38:03

+0

我上面的方法可以幫助你,請試試我的代碼。 – Sovannarith 2013-05-02 06:49:58

+0

感謝您的幫助 – sabeer 2013-05-02 12:26:58

0

您是否嘗試在旋轉委託方法中設置searchBar的框架或在XIB中嘗試自動調整大小。

請參閱this以獲得更好的想法。

+0

最初波泰特模式幀正確的是減少 – sabeer 2013-05-02 05:04:02

相關問題