我有一个 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 的边界内绘制。
关于iphone - 当 UIImageView 离开 UIViewController 的框架时屏蔽它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7548693/