-1
我想將UIImageView添加到UIView,問題在於圖像視圖不在UIViews框架中,所以理論上它應該被隱藏(位於UIView之外的UIImageView部分)。如何將UIImageView添加到UIView而不顯示UIViewBorder之外的UIImageView的內容
這裏是我的代碼:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
firstRectangle = [[UIView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
firstRectangle.hidden = NO;
firstRectangle.backgroundColor = [UIColor yellowColor];
[self.view addSubview:firstRectangle];
[firstRectangle setContentMode:UIViewControllerHierarchyInconsistencyException];
secondRectangle = [[UIImageView alloc] initWithFrame:CGRectMake(0, -[[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
secondRectangle.hidden = NO;
secondRectangle.backgroundColor = [UIColor redColor];
[firstRectangle addSubview:secondRectangle];
UIButton *animateButton = [[UIButton alloc]initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2, 100, 30)];
animateButton.backgroundColor = [UIColor greenColor];
[animateButton addTarget:self action:@selector(animateButtonFunction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:animateButton];
}
- (void)animateButtonFunction{
[UIView animateWithDuration:10.f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[firstRectangle setFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[secondRectangle setFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
}
completion:^(BOOL completed) {
}];
}