Iphone 调整宽度时要调整的UIScrollView高度

Iphone 调整宽度时要调整的UIScrollView高度,iphone,objective-c,ipad,uiscrollview,Iphone,Objective C,Ipad,Uiscrollview,我有一个UIScrollView,我想在调整宽度时按比例调整框架高度,这可能吗?基本上,我说的是在调整UIScrollView的宽度时自动调整UIScrollView的帧高度?我已尝试将autoResizingMask设置为UIViewAutoresizingFlexibleWidth和height,但这不起作用您可以执行以下操作: //get old proportions CGFloat proportion = scrollView.frame.size.width / scrollVie

我有一个UIScrollView,我想在调整宽度时按比例调整框架高度,这可能吗?基本上,我说的是在调整UIScrollView的宽度时自动调整UIScrollView的帧高度?我已尝试将autoResizingMask设置为UIViewAutoresizingFlexibleWidth和height,但这不起作用

您可以执行以下操作:

//get old proportions
CGFloat proportion = scrollView.frame.size.width / scrollView.frame.size.height;

CGRect frame = scrollView.frame;

frame.size.width = new_width;
frame.size.height = new_width * proportion;

scrollView.frame = frame;
你可以做:

//get old proportions
CGFloat proportion = scrollView.frame.size.width / scrollView.frame.size.height;

CGRect frame = scrollView.frame;

frame.size.width = new_width;
frame.size.height = new_width * proportion;

scrollView.frame = frame;

我不认为有一个自动的方法来做这件事。但您可以添加UIView+SCaleAddition来执行此操作:

@interface UIView(RespectScale) - (void)setWidthRespect:(float)w; - (void)setHeightRespect:(float)h; @end @implement UIView(RespectScale) - (void)setWidthRespect:(float)w { float scale = self.bounds.size.width / self.bounds.size.height; float h = w/scale; CGRect bounds = self.bounds bounds.size.width = w; bounds.size.height = h; self.bounds = bounds; } - (void)setHeightRespect:(float)h { // write it your own } @end @界面UIView(比例) -(无效)设置宽度:(浮动)w; -(无效)设置高度方面:(浮动)h; @结束 @实施UIView(比例) -(无效)设置宽度方面:(浮动)w { 浮动比例=self.bounds.size.width/self.bounds.size.height; 浮子h=w/刻度; CGRect bounds=self.bounds bounds.size.width=w; bounds.size.height=h; self.bounds=边界; } -(无效)设置高度方面:(浮动)h { //你自己写吧 } @结束

我认为没有一种自动的方法可以做到这一点。但您可以添加UIView+SCaleAddition来执行此操作:

@interface UIView(RespectScale) - (void)setWidthRespect:(float)w; - (void)setHeightRespect:(float)h; @end @implement UIView(RespectScale) - (void)setWidthRespect:(float)w { float scale = self.bounds.size.width / self.bounds.size.height; float h = w/scale; CGRect bounds = self.bounds bounds.size.width = w; bounds.size.height = h; self.bounds = bounds; } - (void)setHeightRespect:(float)h { // write it your own } @end @界面UIView(比例) -(无效)设置宽度:(浮动)w; -(无效)设置高度方面:(浮动)h; @结束 @实施UIView(比例) -(无效)设置宽度方面:(浮动)w { 浮动比例=self.bounds.size.width/self.bounds.size.height; 浮子h=w/刻度; CGRect bounds=self.bounds bounds.size.width=w; bounds.size.height=h; self.bounds=边界; } -(无效)设置高度方面:(浮动)h { //你自己写吧 } @结束

你是如何“调整”scrollview的宽度的?你是如何“调整”scrollview的宽度的?这就是我所做的,但我想知道是否有一种自动方法,而不必这么做,你可以应用CGAffineTransformScale,但除此之外,我不这么认为。这就是我所做的,但是我想知道是否有一种自动的方法不需要做得很好,你可以应用CGAffineTransformScale,但除此之外,我不这么认为。