开发者

how i can move label over all view

开发者 https://www.devze.com 2023-04-05 01:35 出处:网络
My view layouthttp://i.imgur.com/PkZ9P.png -(IBAction)tapview:(id)sender { [UIView beginAnimations:nil context:nil];

My view layout http://i.imgur.com/PkZ9P.png

    -(IBAction)tapview:(id)sender  
   {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:1];
    CGRect frame = labelgreen.frame;
    frame.origin.y -= 200;
    la开发者_如何学Gobelgreen.frame = frame;
    [UIView setAnimationDidStopSelector:@selector(forview1)];  
    [UIView commitAnimations]; }

but when label move it move only inside view1 or view2 or view 3, i would like to let it move over all view to color view

what i should do?

and after animation finish it should run function -(void)forview1

but the function is not call

-(void)forview1

{colorview.backgroundcolor=changecolor;}

thank you


Spelling mistake in ur function

NOT

[UIView setAnimationDidStopSelector:@selector(foeview1)];  

//correct

[UIView setAnimationDidStopSelector:@selector(forview1)];  

more over

replace this line

  labelgreen.frame.frame = frame;

To

  labelgreen.frame = frame;

declare this function in ur .h

-(void)forview1;


First, try to replace

[UIView setAnimationDidStopSelector:@selector(foeview1)];  

with

[UIView setAnimationDidStopSelector:@selector(forview1)];

Second, push label on the top of views using following method

- (void)bringSubviewToFront:(UIView *)view

For example:

UILabel * labelgreen;
[labelgreen.superview bringSubviewToFront:labelgreen];

If you are creating this view in IB then just drag UILabel to the bottom of its subviews.


You should use block based animations. Those functions are deprecated.

[UIView animateWithDuration:animationDuration animations:^{

}];


The label views are nested inside View1/View2/View3 and thus are clipped to the bounds of those containing views. To make them move around the outer view you will need to either start them off in the main view, or before starting the animation remove them from the containing views and add them to the outer view. You could also look into whether the clipToBounds property can be used to have the label views render when they are moved out of the bounds of their containing view.

Example of removing and re-adding in containing view (assuming the labelgreen view is inside a view called view2) (do this before you start your animation).

CGRect newframe = labelgreen.frame
newframe.origin.y = newframe + view2.frame.origin.y;
newframe.origin.x = newframe + view2.frame.origin.x;

[labelgreen removeFromSuperview];
labelgreen.frame = newframe;

Then either:

[colorview addSubview:labelgreen];  // (assuming colorview is your main containing view).

Or:

[self.view addSubview:labelgreen];  // if self.view is the main containing view
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号