以下是我的一些视图控制器: tabBarController , navigationBarController , viewController 和 imageView 。<登记/> 层次结构是: tabBarController 是根控制器,它包括 navigationBarController 。并且 viewController (包括 imageView )由 navigationBarController 推送。
所以问题是,当我触摸 imageView 时,如何使用流畅的动画将其调整为全屏。注意,我不想隐藏NavigationBar&amp;的TabBar。
我在setFrame
尝试了它,但它由 navigationBarController 和 tabBarController 覆盖。
我试过了presentModalViewController:
,但却失去了连续性
我还尝试将rootViewController
重置为 viewController ,但结果是动画损坏了。 :(
谢谢你的任何建议!
UIViewController * viewController = [[UIViewController alloc] init];
[viewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[viewController.view setBackgroundColor:[UIColor redColor]];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
[imageView setBackgroundColor:[UIColor yellowColor]];
[imageView setUserInteractionEnabled:YES];
[viewController.view addSubview:imageView];
[imageView release];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
UIViewController * anotherTabViewController = [[UIViewController alloc] init];
[anotherTabViewController.view setFrame:CGRectMake(0.0f, 0.0, 320.0f, 480.0f)];
[anotherTabViewController.view setBackgroundColor:[UIColor blueColor]];
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, anotherTabViewController, nil];
[navigationController release];
[anotherTabViewController release];
[self.window setRootViewController:tabBarController];
这里我写了一个简单的测试代码。现在不关心触摸动作。我想知道如何将imageView设置为全屏(宽度:320,高度:480)。但它被导航栏和标签栏修剪。我知道框架是相对于它的超级视图。如何处理这个问题?
答案 0 :(得分:2)
尝试将img添加到您的窗口,当您需要将其调整为全屏时:
UIImageView *img; //create new image
img = yourImageView;
[img setOrigin:CGPointMake(yourImageView.frame.origin.x, yourImageView.frame.origin.y+90)];
//window size is bigger, so to set an image frame visionary at same place, you need to set origin point lower
MOEAppDelegate *sharedAppDelegate = (MOEAppDelegate *)[[UIApplication sharedApplication] delegate];
[sharedAppDelegate.window addSubview:img];
[UIView animateWithDuration:1
animations:^{
[img setFrame:CGRectMake(0,
0,
320,
480)];
}];
注意,当你添加tabBar或navigationBar时,你的self.view的框架会自动调整大小,而在 - (void)viewDidLoad中,它不会调整大小的喷射!