我为ViewDidload
中的所有UI元素设置框架,并在
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
问题是,当我尝试从View A --> View B
纵向导航时,然后将方向风景更改为“视图A <-视图B”。然后,帧没有相应地改变。
我尝试添加
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
但是,即使复出时viewWillTransitionToSize未被调用,框架仍然没有改变。
- (void)viewDidLoad {
[super viewDidLoad];
scrollView = [UIScrollView new];
scrollView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-hSelecViewHeight);
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.bounces = true;
scrollView.alwaysBounceVertical = true;
[self.view addSubview:scrollView];
imagePager = [[KIImagePager alloc]init];
imagePager.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width*0.563);
imagePager.delegate = self;
imagePager.dataSource = self;
imagePager.slideshowTimeInterval = 2.0;
[imagePager setImageCounterDisabled:true];
[scrollView addSubview:imagePager];
-- and few other UI elements also --
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.barTintColor = barColor;
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
hSelView.frame = CGRectMake(0,self.view.frame.size.height-hSelecViewHeight,self.view.frame.size.width,hSelecViewHeight);
scrollView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-hSelecViewHeight);
imagePager.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width*0.563);
[hSelView reloadData];
if (categoryIndex!=0){
tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, (259*[[arrListData valueForKey:@"sub_category_name"] count])+100);
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, ([[arrListData valueForKey:@"sub_category_name"] count]*259)+100)];
}else{
tableView.frame = CGRectMake(0, imagePager.frame.origin.y+imagePager.frame.size.height+1, self.view.frame.size.width, (259*[[arrList valueForKey:@"name"]count])+100);
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, ([[arrList valueForKey:@"name"]count]*259)+(self.view.frame.size.width*0.563-40)+100)];
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"orientation:- %ld",(long)orientation);
if (!isMaximized) {
content.view.frame = CGRectMake(self.view.frame.size.width-(self.view.frame.size.width/1.5)-10, self.view.frame.size.height-hSelecViewHeight-10-((self.view.frame.size.width/1.5)*0.563), self.view.frame.size.width/1.5, (self.view.frame.size.width/1.5)*0.563);
closePopButton.frame = CGRectMake(content.view.frame.size.width-40, 5, 36, 36);
hSelView.frame = CGRectMake(0,self.view.frame.size.height-hSelecViewHeight,self.view.frame.size.width,hSelecViewHeight);
scrollView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-hSelecViewHeight);
imagePager.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width*0.563);
[hSelView reloadData];
if (categoryIndex!=0){
tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, (259*[[arrListData valueForKey:@"sub_category_name"] count])+100);
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, ([[arrListData valueForKey:@"sub_category_name"] count]*259)+100)];
}else{
tableView.frame = CGRectMake(0, imagePager.frame.origin.y+imagePager.frame.size.height+1, self.view.frame.size.width, (259*[[arrList valueForKey:@"name"]count])+100);
[scrollView setContentSize:CGSizeMake(self.view.frame.size.width, ([[arrList valueForKey:@"name"]count]*259)+(self.view.frame.size.width*0.563-40)+100)];
}
}
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context)
{
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
答案 0 :(得分:0)
请在viewWillAppear方法中添加更新的代码。
- (void)viewWillAppear:(BOOL)animated
{
}
答案 1 :(得分:0)
在viewWillTransitionToSize
中调用viewWillAppear
方法
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self viewWillTransitionToSize:self.view.frame.size withTransitionCoordinator:[self transitionCoordinator]];
}