2012-05-24 33 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视图的帧,然后添加按钮,然后尝试改变方向。