Question: My code goes like this:

```
- (void)viewDidLoad
{
  [self setGridView];
}
-(void)setGridView
{
  CGRect frame; 
  frame .origin.x=0;
  frame.origin.y=20;
  frame.size.width=GRID_WEIGHT;
  frame.size.height=GRID_HEIGHT;
  GridView *ObjGridView=[[GridView alloc]initWithFrame:frame]; 

  [[NSBundle mainBundle ] loadNibNamed:@"GridView" owner:ObjGridView options:nil];
  [ObjGridView setGridViewFrame:frame];

  [self.view addSubview:ObjGridView.GridCellView];
  frame .origin.x+=GRID_WEIGHT;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
  return YES;
}

```

This code adds a subview to a view and sets the frame

My problem:
1-How do i refresh my view when Orientation(landscape or portrait) happens,
because i set the frame of subview in the lanscape mode and i wants to use the sane view in my portrait view also .(basically where do i call this -(void)setGridView delegate method)?

2-How do i know, my subview exceeding the bound of the view,so that i can handle the subview in my setGridView method ?

Answer: 
In `viewDidLoad`

```
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(OrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

```

Method for notify you that Orientation Changed:-

```
-(void)OrientationChange:(NSNotification*)notification
{
    UIDeviceOrientation Orientation=[[UIDevice currentDevice]orientation];

    if(Orientation==UIDeviceOrientationLandscapeLeft || Orientation==UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"Landscape");
    }
    else if(Orientation==UIDeviceOrientationPortrait)
    {
        NSLog(@"Portrait");
    }
}

```
In response to your questionsL

With regard to resizing on orientation change:
If you set your springs and struts accordingly it should autoresize automatically, alternatively you can do this in code as per deamonsarea's answer

To check if a view is exceeding the bounds of the superview use CGRectContainsRect
something like.

```
CGRect frame0 = self.view.bounds;
CGRect frame1 = ObjGridView.frame;
if(CGRectContainsRect(frame0,frame1)==NO){
  NSLog(@"exceeds bounds")
}

```

Also noticed you are not calling [super viewDidLoad] and this line

```
[[NSBundle mainBundle ] loadNibNamed:@"GridView" owner:ObjGridView options:nil];

```

loads a new instance of the view but you are not refering to it anywhere