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

标签 iphone ios cocoa-touch

我有一个 Advertisement 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){

                     }

     ];




}

应用委托(delegate):

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

最佳答案

将( View Controller 的) View 上的 clipsToBounds 属性设置为 YES。 View 的 subview 将仅在 View 的边界内绘制。

UIView documentation

关于iphone - 当 UIImageView 离开 UIViewController 的框架时屏蔽它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7548693/

相关文章:

iphone - iOS4 sleep 时 Wifi 连接无法保持

ios - 在我的例子中,ISO 时间戳应该使用什么格式

objective-c - 长按 UI 元素(或如何确定按下的是哪个元素?)

iphone - 查找最小/最大纬度和经度

objective-c - 适用于 iOS 和 Mac OS X 的 MacBinary 转换器

iphone - 构建错误 - 文件中缺少所需的架构 i386

iphone - 在 NSObject 类中显示一个 UIAlertView

iphone - 如果方法的返回类型是 NSArray,那么将返回值类型从 NSMutableArray 转换为 NSArray 是一个好习惯吗?

html - 输入文本在 iphone safari 和 chrome 浏览器中不可见

ios - 我们应该如何显示以下 ViewController?