在拆分视图应用程序中隐藏主视图..?

时间:2010-06-11 06:18:28

标签: iphone objective-c ipad

我创建了基于拆分视图的ipad应用程序,其中主视图是表格视图,而详细信息视图显示图像..我需要在横向模式下显示适合屏幕100%的图像。 这可能是按钮事件或双击事件..我应该怎么做。 提前致谢。

1 个答案:

答案 0 :(得分: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