ios - How to add a UIImageView to a UIView without displaying the content of the UIImageView that is outside of the UIViewBorder -
i trying add uiimageview uiview, problem image view outside of uiviews frame, theoretically should hidden (the part of uiimageview situated outside of uiview).
here code:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically 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) { }]; }
fixed problem, here code:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically 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]; firstrectangle.bounds = cgrectmake(0, [[uiscreen mainscreen] bounds].size.height, [[uiscreen mainscreen] bounds].size.width, [[uiscreen mainscreen] bounds].size.height); firstrectangle.clipstobounds = yes; [self.view addsubview:firstrectangle]; secondrectangle = [[uiview alloc] initwithframe:cgrectmake(0, 0, [[uiscreen mainscreen] bounds].size.width, [[uiscreen mainscreen] bounds].size.height)]; secondrectangle.hidden = no; secondrectangle.backgroundcolor = [uicolor redcolor]; secondrectangle.layer.borderwidth = 5.f; secondrectangle.layer.bordercolor = [[uicolor greencolor] cgcolor]; [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{ nslog(@"test"); [uiview animatewithduration:.6f delay:0.0f options:uiviewanimationoptioncurvelinear animations:^{ [firstrectangle setbounds:cgrectmake(0, 0, [[uiscreen mainscreen] bounds].size.width, [[uiscreen mainscreen] bounds].size.height)]; [firstrectangle setframe:cgrectmake(0, 0, [[uiscreen mainscreen] bounds].size.width, [[uiscreen mainscreen] bounds].size.height)]; } completion:^(bool completed) { }]; }
- one of problem needed add cliptobounds , bounds properties code.
- then tweaked code obtain wished animation, hope these code others in implementing transition or different animation.
Comments
Post a Comment