UIView not resizing in code or interface builder
I am creating a simple UIView and adding it to my main view - I am also changing the frame however no matter what I try it doesn't resize the view - it just lumps this huge view down onto my superview. Changing the view size in interface builder has no effect either:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
Hote开发者_如何学ClInformationViewController *vc =
[[HotelInformationViewController alloc]initWithNibName:@"HotelInformationViewController"
bundle:nil control:control];
[self.view addSubview:vc.view];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil control:(UIControl *)control
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
self.view.bounds = CGRectMake(control.frame.origin.x, control.frame.origin.y, 286, 286); //This is the size I want to view to be 286, 286
}
return self;
}
the problem is that you are trying to change the bounds, and you are supposed to change the frame. Bounds is rect in internal view that should be projected to the rect in superview - a frame. Imagine picture of size 300x300. If you have a view on the screen with frame (0,0,100,100) and you want to show the central part of that picture you should set bounds to (150,150, 100,100). As a result you will see the central part of you picture (without resizing) shown in a rect with size 100x100 in upper left corner of a superview.
You should be calling self.view.frame = CGRectMake(...)
. frame
is the property that represents position and size of the view within its superview, and is the thing you change to move or resize a view.
(The bounds
attribute is the internal boundaries of the view's coordinate system that the frames of the view's subviews exist within, and it's rarely if ever necessary to explicitly set it)
精彩评论