2012-01-17 18 views
1

私はUIScrollViewを持っており、幅を調整するときにフレームの高さを比例的に調整したいと考えていました。基本的には、私はUIScrollViewの幅を調整するときに、UIScrollViewのフレームの高さを自動調整することについて話していますか?私はUIViewAutoresizingFlexibleWidthと高さにautoResizingMaskを設定しようとしたが、これはあなたが行うことができます幅が調整されるときに調整するUIScrollViewの高さ

+0

はどのようにあなたがscrollviewの「幅を調整」されていますが、あなたはこれを行うには、UIViewの+ SCaleAdditionを追加することができますか? –

+0

scrollView.frame.size.width – adit

答えて

1

私はそれを行うための自動的な方法はないと思います。

 
@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 

0

を動作しません:

//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; 
+0

これは私がやったことですが、これを行う必要がない自動方法があるのだろうかと疑問に思っていました。 – adit

+0

CGAffineTransformScaleを適用することはできますが、それ以外はそうは思いません。 –

関連する問題