2010-06-11 87 views
1

我已經創建了基於ipad應用的分割視圖,其中主視圖是表視圖,而細節視圖顯示圖像..我需要在橫向模式下顯示適合屏幕100%的圖像。 這可能是在按鈕事件或雙擊事件..我應該怎麼做。 在此先感謝。在分割視圖應用中隱藏主視圖..?

+0

我已經使用等作爲模態的視圖.. [自我presentModalViewController:自動畫:YES]; 但它的問題是,當我駁回彈出分割視圖只顯示根視圖不與細節視圖一起。 – Mahesh 2010-06-11 07:52:04

回答

4

通過在您的應用中使用包含分割視圖的主窗口頂部按需顯示的輔助窗口,您可以完成所需的任務。

創建一個新的UIWindow &一個新的UIViewController。將UIViewController的視圖添加到新窗口中,將窗口級別設置爲正值(1或更大),使其位於主窗口的頂部,然後將新窗口置於屏幕上。如果將窗口背景顏色設置爲[UIColor clearColor],並將圖像放置在新的UIViewController中的視圖中,則直接位於詳細視圖中的圖像頂部,那麼用戶將不會注意到任何新事件發生。然後,您可以將圖像幀動畫化爲全屏或做任何你想做的事情。我們有時會使用此技術來支持拖放或我們自己的自定義模式視圖控制器,但它也適用於您的目的。

下面是一個例子:

@interface MyViewController : UIViewController @end 


@interface AppDelegate : NSObject <UIApplicationDelegate> { 
    MyViewController   *overlayController; 
    UIWindow     *overlayWindow; 

    UIWindow     *window;    // the main window that contains your splitview 
    UINavigationController  *navigationController; // or split view contoller, whatever, your main controller 
} 

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 
@property (nonatomic, retain) IBOutlet UIWindow *window; 

@end 


@implementation MyViewController 

- (void) loadView { 
    self.view = [[[UIView alloc] initWithFrame: CGRectZero] autorelease]; 
    self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; 
    self.view.backgroundColor = [UIColor redColor]; 
} 

@end 


@implementation AppDelegate 

@synthesize window, navigationController; 


- (void) click:(id) sender { 
    [overlayController.view removeFromSuperview]; 
    [overlayController release]; 
    overlayController = nil; 

    overlayWindow.hidden = YES; 
    [overlayWindow release]; 
    overlayWindow = nil; 
} 


- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // Add the navigation controller's view to the window and display. 
    // standard stuff... 
    [self.window addSubview: navigationController.view]; 
    [self.window makeKeyAndVisible]; 

    // add the overlay window 
    // note that both the overlay window and controller are retained until we dismiss 
    // the window, this is important! 
    overlayWindow = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].applicationFrame]; // or [UIScreen mainScreen].bounds, depending on what you want 
    overlayController = [MyViewController new]; 
    overlayController.view.frame = overlayWindow.bounds; 

    UIButton *button = [UIButton buttonWithType: UIButtonTypeRoundedRect]; 

    [button addTarget: self action: @selector(click:) forControlEvents: UIControlEventTouchUpInside]; 
    [button setTitle: @"Done" forState: UIControlStateNormal]; 
    button.frame = CGRectMake(0, 0, 100, 50); 
    button.center = overlayController.view.center; 

    [overlayController.view addSubview: button]; 

    // the controller's view is the first and only view in the 
    // new window. this ensures you get rotation events. Add any subviews 
    // that will appear in the new window to overlayContoller.view 
    [overlayWindow addSubview: overlayController.view]; 
    [overlayWindow setWindowLevel: 1]; 
    [overlayWindow makeKeyAndVisible]; 

    return YES; 
} 


- (void)dealloc { 
    [overlayController release]; 
    [overlayWindow release]; 
    [navigationController release]; 
    [window release]; 
    [super dealloc]; 
} 


@end 
+0

您的應用程序支持旋轉嗎?這個想法很好,但使用兩個窗口,我認爲它會得到旋轉問題。雖然我通過將詳細視圖幀寬度及其x來源更改爲0來解決我的問題。 – Mahesh 2010-12-09 11:44:40

+0

只要每個窗口只有一個視圖,旋轉就可以了 – par 2010-12-09 21:01:29