2012-05-24 32 views
0

我有一個ViewController,它調用另一個包含contentView,然後webView的視圖。我正在嘗試在webView之上添加按鈕,並試圖讓它們在自動調整大小掩蔽的情況下工作大約兩個小時,但沒有成功。當我試圖重置框架旋轉時,按鈕需要幾分鐘的時間重新定位,所以它看起來很滯後。這裏是我的init方法的觀點:Autoresize Masking問題

self = [super initWithFrame:frame]; 
    if (self) { 
     _contentView = [[UIView alloc] initWithFrame:frame]; 
     _contentView.backgroundColor = [UIColor whiteColor]; 
     _contentView.clipsToBounds = YES; 
     self.clipsToBounds = YES; 

     UIImage *facebookShare = [UIImage imageNamed:@"share_facebook_focus_pad"]; 
     self.facebookButton = [[UIButton alloc] initWithFrame:CGRectMake(700, 150, facebookShare.size.width, facebookShare.size.height)]; 
     //[facebookButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin]; 
     [self.facebookButton setImage:facebookShare forState:UIControlStateNormal]; 
     [_webView addSubview:self.facebookButton]; 

     UIImage *twitterShare = [UIImage imageNamed:@"share_twitter_focus_pad"]; 
     self.twitterButton = [[UIButton alloc] initWithFrame:CGRectMake(self.facebookButton.frame.origin.x, self.facebookButton.frame.origin.y + facebookShare.size.height, twitterShare.size.width, twitterShare.size.height)]; 
     //twitterButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.twitterButton setImage:twitterShare forState:UIControlStateNormal]; 
     [_webView addSubview:self.twitterButton]; 

     UIImage *mailShare = [UIImage imageNamed:@"share_mail_focus_pad"]; 
     self.mailButton = [[UIButton alloc] initWithFrame:CGRectMake(self.facebookButton.frame.origin.x, self.facebookButton.frame.origin.y + facebookShare.size.height + twitterShare.size.height, mailShare.size.width, mailShare.size.height)]; 
     //mailButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     [self.mailButton setImage:mailShare forState:UIControlStateNormal]; 
     [_webView addSubview:self.mailButton]; 

     [_contentView addSubview:_webView]; 
     [self addSubview:_contentView]; 

     self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
     self.webView.frame = CGRectMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame), CGRectGetWidth(self.frame), CGRectGetHeight(self.frame)); 

    } 

只是簡單地添加上的_webView頂部三個按鈕。我試圖讓他們在右上角,因此,我需要掩蓋leftbottom。在這裏我評論了twitter和郵件按鈕,然後用Facebook按鈕進行測試。我特別是將Facebook按鈕設置爲X座標700 - 然而,只要我取消註釋如上所示的自動大小屏蔽行,Facebook按鈕消失!這是如何發生的?除非已經旋轉,否則自動調整大小的蒙版不會與x座標一起玩耍!即使如此,它應該很好地對齊它,並將其推到右上角,因爲我掩蓋了左側和底部。這是怎麼回事?這是非常令人沮喪的 - 我已經與它鬥爭了大約2個小時!

P.S:我沒有使用Interface Builder。請不要暗示我使用它。

+0

你的超級視圖是否有autoresizesSubviews設置爲YES? –

+0

@OmarAbdelhafith是的 – darksky

回答

0

嘗試

self.facebookButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

和首先設置web視圖的幀,然後添加按鈕,然後嘗試改變方向。