2011-09-25 49 views
0

我有一个Advertisement UIViewController类,它包含下面的代码。该框架是图像的确切尺寸。当它动画下来时,我希望它在76.0点消失。我使UIViewController的框架与图片的大小相同,但当它向下滑动时,它不会遮挡任何图片。当它离开UIViewController的框架时掩盖UIImageView

如何使它在离开UIViewController框架时看不到uiimageview?

-(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]; 

回答

2

设置在视图(的视图 - 控制)为YES clipsToBounds属性。该视图的子视图将仅在视图的范围内绘制。

UIView documentation