2011-09-13 34 views
1

我的看法布局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; 
    labelgreen.frame = frame; 
    [UIView setAnimationDidStopSelector:@selector(forview1)]; 
    [UIView commitAnimations]; } 

但是当标签移动它只能移动内部厂景或视图2或视图3, 我想告诉所有视图移动到颜色查看

我该怎么办?

和动画完成后,它应该运行功能-(void)forview1

但功能不是叫

-(void)forview1 

{colorview.backgroundcolor=changecolor;} 

谢谢

回答

0

拼写错误在乌尔功能

[UIView setAnimationDidStopSelector:@selector(foeview1)]; 

//正确

[UIView setAnimationDidStopSelector:@selector(forview1)]; 

更超过

替换该行

labelgreen.frame.frame = frame; 

labelgreen.frame = frame; 

声明此功能在乌拉圭回合的.h

- (void)forview1;

+0

[UIView的setAnimationDidStopSelector:@selector(forview1)]; 我尝试但不工作。 – MAXZZXAM

+1

是否在.h文件中声明该方法 –

+0

不,我只是声明,但我尝试在.h中声明并且它工作正常。谢谢你 – MAXZZXAM

0

首先,尝试

[UIView setAnimationDidStopSelector:@selector(foeview1)]; 

[UIView setAnimationDidStopSelector:@selector(forview1)]; 

二,关于视图的顶推标签使用,以取代以下方法

- (void)bringSubviewToFront:(UIView *)view 

例如:

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

如果您在IB中创建此视图,只需将UILabel拖动到其子视图的底部。

0

您应该使用基于块的动画。这些功能已被弃用。

[UIView animateWithDuration:animationDuration animations:^{ 

}]; 
+0

你能举个例子来把我的功能翻译成上述功能 – MAXZZXAM

0

标签视图嵌套在View1/View2/View3中,因此被剪裁到包含视图的边界。为了使它们在外部视图中移动,您需要在主视图中将其启动,或者在开始动画之前将它们从包含视图中移除并将它们添加到外部视图。您还可以查看是否可以使用clipToBounds属性在标签视图移出其包含视图的范围时使其呈现。

在包含视图中移除和重新添加的示例(假设labelgreen视图位于名为view2的视图内)(在开始动画之前执行此操作)。

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; 

然后:

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

或者:

[self.view addSubview:labelgreen]; // if self.view is the main containing view 
相关问题