I have an Advertisement UIViewController class that contains the following code. The frame is the exact dimension of the image. When it animates down I want it to disappear at the 76.0 point. I made the UIViewController’s frame the same size as the image too, but it doesn’t obscure any of the image when it slides down.
How do I make it so that I cannot see the uiimageview when it leaves the UIViewController frame?
-(void)viewDidLoad{
UIImageView *ad = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 76.0)];
ad.image = [UIImage imageNamed:@"advertisement.jpg"];
[self.view addSubview:ad];
[ad release];
[UIView animateWithDuration:1.0 //animate the content offset
delay:6.0
options:UIViewAnimationCurveEaseIn
animations:^{
ad.frame = CGRectMake(0.0, 152.0, 320.0, 76.0); }
completion:^(BOOL finished){
}
];
}
Appdelegate:
Advertisement *theAdView = [[Advertisement alloc] init];
theAdView.view.frame = CGRectMake(0.0, self.window.frame.size.height-120.0, 320.0, 76.0);
[self.window addSubview:theAdView.view];
Set the
clipsToBoundsproperty on the view (of the viewcontroller) to YES. Subviews of the view will then be drawn only within the bounds of the view.UIView documentation