当它离开UIViewController的框架时屏蔽UIImageView

时间:2011-09-25 21:19:51

标签: iphone ios cocoa-touch

我有一个广告UIViewController类,其中包含以下代码。框架是图像的精确尺寸。当它动画下来时,我希望它在76.0点消失。我使UIViewController的框架与图像的大小相同,但它在向下滑动时不会遮挡任何图像。

如何制作它以便在离开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];

1 个答案:

答案 0 :(得分:2)

将视图(viewcontroller)的clipsToBounds属性设置为YES。然后,视图的子视图将仅在视图的范围内绘制。

UIView documentation