2012-11-21 45 views
2

这只是一个测试项目之前,我落实到更大的东西:-)IOS - 调整自定义视图编程

按我创建内部1视图控制器2点自定义视图图像。我需要它们重叠,或者至少在应用程序内移动并返回。

我试过查找自定义视图,但我有很多运气。

我希望使用此代码或类似的东西:

-(IBAction)move02Action 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
     _left.view.frame = CGRectMake(80, 70, 160, 380); //_left is Left UIViewContorller 
     _right.view.frame = CGRectMake(240, 70, 160, 380); //_right is Right UIViewContorller 
    [UIView commitAnimations]; 
} 

我意识到,这是UIViews而不是视图控制器。任何想法在哪里看?

Storyboard

感谢您的洞察力:-)

回答

1

您可以使用遏制视图控制器这样

UIView *view = [[UIView alloc] initWithFrame:CGRectMake((80, 70, 160, 380))]; 
[view setBackgroundColor:[UIColor whiteColor]]; 
[self.view addSubview:view]; 

LeftViewController *left = [[LeftViewController alloc] init]; 

left.view.frame = view.bounds; 
[left setDelegate:self]; 
[view addSubview:left .view]; 

[left didMoveToParentViewController:self]; 
[self addChildViewController:left ]; 

退房的"Implementing a Container View Controller"文档。

EDIT

1)添加一个滚动型到self.view并添加在滚动视图的两个视图与不同帧使用上面所建议的代码以添加意见。

2)设置内容关闭滚动查看,必要时这样

CGPoint bottomOffset = CGPointMake(scrolposition, scrollView.contentSize.height - scrollnView.bounds.size.height); 
    [scrollView setContentOffset:bottomOffset animated:NO]; 

集,如果你想超精研视图使用[[self view] bringSubviewToFront:[self LeftView]];[[self view] sendSubviewToBack:LeftView];

+0

我一直在你的答案玩弄的效果,但添加了第三个视图,并操作已经存在的2。 –

+0

@JeffKranenburg检查编辑的答案 – vamsi575kg

+0

好吧我会研究 - 更令人费解的:-)我会更新它,当我得到它的怀疑 –