调整
大小后如何刷新UIViewController
视图?我需要一种类似于UITableViewController
reloadData
的方法。
是否有其他可能性可以在不重新加载的情况下调整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
做好重新构图,但不要重新加载。
尝试
[self.view setNeedsDisplay];
这将为您解决问题!
[self.view setNeedsDisplay];