自动调整屏蔽问题

时间:2012-05-24 21:25:03

标签: iphone objective-c ipad uiview autoresizingmask

我有一个ViewController调用另一个视图,其中包含contentView,然后是webView。我正在尝试在webView之上添加按钮,并试图让它们使用自动调整大小屏蔽大约两个小时,但没有成功。当我试图在旋转时重置框架时,按钮需要几分钟才能重新定位,因此它看起来很迟钝。这是视图的init方法:

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。在这里,我评论了推特和邮件按钮,只是用Facebook按钮测试它。我特别将Facebook按钮设置为x坐标700 - 但是一旦我取消注释自动调整大小掩码行,如上所示,Facebook按钮就会消失!这是怎么发生的?除非已旋转,否则自动调整遮罩不会与x坐标一起使用!即使它,它应该很好地对齐它并将它推到右上方,因为我掩盖了左下角。这是怎么回事?这非常令人沮丧 - 我已经和它争斗了大约2个小时!

P.S:我没有使用Interface Builder。请不要建议我使用它。

1 个答案:

答案 0 :(得分:0)

尝试

self.facebookButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

首先设置webview的框架,然后添加按钮,然后尝试更改方向。