在调整大小后,如何刷新UIViewController
的观点?我需要一种与reloadData
中的UITableViewController
类似的方法。
是否有其他方法可以在不重新加载的情况下调整UIViewController
的视图大小?
我的代码是:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
orientation = toInterfaceOrientation;
if(orientation==3 || orientation==4)
{
heightBoxDimension1 = [GlobalData sharedGlobalData].heightLandscape;
widthBoxDimension1 = [GlobalData sharedGlobalData].widthLandscapeBig;
widthBoxDimension2 = [GlobalData sharedGlobalData].widthLandscapeSmall;
}
else
{
heightBoxDimension1 = [GlobalData sharedGlobalData].heightPortrait;
widthBoxDimension1 = [GlobalData sharedGlobalData].widthPortraitBig;
widthBoxDimension2 = [GlobalData sharedGlobalData].widthPortraitSmall;
}
for(UIView* view in self.view.subviews)
{
NSLog(@"%.0f %.0f %.0f %.0f ", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
if(view.frame.size.width >400)
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, widthBoxDimension1, heightBoxDimension1)];
NSLog(@"%.0f %.0f %.0f %.0f ", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
}
else
{
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, widthBoxDimension2, heightBoxDimension1)];
NSLog(@"%.0f %.0f %.0f %.0f ", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
}
}
[self.view setNeedsDisplay];
}
我有一类全局变量,其中我放置了视图的静态维度,我有两种类型的视图,具有相同的高度但不同的宽度。当转动模拟器时输入此方法,但在更改视图框架后,请不要重新加载这些视图......
控制台的输出是:
2012-06-05 10:53:09.309 TemplateiPad2[12561:207] 8 8 752 318
2012-06-05 10:53:09.309 TemplateiPad2[12561:207] 8 8 752 446
2012-06-05 10:53:09.309 TemplateiPad2[12561:207] 8 334 372 318
2012-06-05 10:53:09.309 TemplateiPad2[12561:207] 8 334 372 446
重做好框架,但不要重装。
答案 0 :(得分:0)
尝试
[self.view setNeedsDisplay];
答案 1 :(得分:0)
这将为您解决问题!
[self.view setNeedsDisplay];