I have a ViewController which calls another view which contains a contentView
and then a webView
on top. I am trying to add buttons on top of webView
and been trying to get them to work with auto resize masking for about two hours now with no success. When I tried to reset the frame upon rotation, the buttons takes a few minutes to reposition so it looks laggy. Here's my init
method for the view:
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));
}
Simply just adding three buttons on top of _webView
. I am trying to have them at the top right corner and therefore, I need to mask left
and bottom
. In here I commented out twitter and mail buttons and just testing it out with Facebook button. I specifically set the the Facebook button to be at x-coordinate 700 - yet as soon as I uncomment the autoresize mask line as shown above, the Facebook button disappears!! How does this happen? Autoresize mask does not play around with the x-coordinate unless it has been rotated! And even though, it should nicely align it according and push it to the top-right as I masked left and bottom. What is going here? This is extremely frustrating - I've been battling with it for about 2 hours!
P.S: I am not using Interface Builder. And please do not suggest that I use it.
try
and set the frame of the webview first and then add the buttons and then try changing the orientation.