0

contentViewを上に含む別のビューを呼び出すViewControllerがありますwebView。上にボタンを追加しようとしてwebViewいますが、自動サイズ変更マスキングでボタンを機能させるために約2時間試しましたが、成功しませんでした。回転時にフレームをリセットしようとすると、ボタンの位置を変更するのに数分かかるため、ボタンが遅く見えます。ビューの私の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));

    }

の上に3つのボタンを追加するだけです_webView。右上隅に配置しようとしているので、マスクleftしてbottom。ここでは、Twitterとメールのボタンをコメントアウトし、Facebookのボタンでテストしました。特にFacebookボタンをx座標700に設定しましたが、上記のように自動サイズ変更マスクラインのコメントを解除するとすぐに、Facebookボタンが消えます!! これはどのように起こりますか?自動サイズ変更マスクは、回転されていない限り、x座標で再生されません。とはいえ、左右をマスクしたので、それに合わせてうまく位置合わせし、右上に押し込む必要があります。ここで何が起こっているのですか?これは非常に苛立たしいことです-私はそれと約2時間戦ってきました!

PS:私はInterfaceBuilderを使用していません。そして、私がそれを使うことを提案しないでください。

4

1 に答える 1

0

試す

self.facebookButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

最初にwebviewのフレームを設定してからボタンを追加してから、向きを変更してみてください。

于 2013-04-01T13:22:55.107 に答える