我有一个 ViewController 调用另一个视图,该视图包含 a contentView
,然后是webView
顶部的 a 。我正在尝试在顶部添加按钮,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
. 我试图将它们放在右上角,因此,我需要屏蔽left
和bottom
. 在这里,我注释掉了 twitter 和邮件按钮,并使用 Facebook 按钮对其进行了测试。我专门将 Facebook 按钮设置为 x 坐标 700 - 但是一旦我取消注释自动调整大小蒙版线,如上所示,Facebook 按钮就会消失!!这是怎么发生的?除非已旋转,否则自动调整蒙版不会与 x 坐标一起使用!尽管如此,它应该很好地对齐它并将它推到右上角,因为我掩盖了左下角。这是怎么回事?这非常令人沮丧 - 我已经与它战斗了大约 2 个小时!
PS:我没有使用界面生成器。请不要建议我使用它。