看了好久 在网上看了很多代码。。也不知道他们在说什么。。主要我想要实现的是用 scrollview 来加载 由别外的controller 生成的view 一开始是不知道怎么获取view 从网上找的例子又太深奥了 哎。。。你真是一只猪!!!要加努力才行!!
为一个controller 命名
UIViewController* viewController1=[self.storyboard instantiateViewControllerWithIdentifier:@"navi1"]; ;
UIView* view1 = viewController1.view;
通过以上两句就可以生成一个view 了
要用scrollview 之前一定要先去了解一下 frame bound rect 这些坐标和相对位置的知识。。。不然要吃大亏的!
见 点击打开链接
- (void)viewDidLoad
{
[super viewDidLoad];
self.scrollView = [[UIScrollView alloc] initWithFrame: self.view.bounds];//生成一个scrollview
//为这个scrollview 设置大小与基本属性
self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame) * 2, CGRectGetHeight(self.view.frame));
self.scrollView.backgroundColor = [UIColor clearColor];
self.scrollView.pagingEnabled = YES;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
//将这个scrollview 加入 原来的view 中
[self.view addSubview: self.scrollView];
//生成两个view 根据自己已经设置好的controller
UIViewController* viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"navi1"]; ;
UIView* view = viewController.view;
view.userInteractionEnabled = YES;
view.frame = self.view.bounds;
//设置它在父视图中的位置坐标
view.frame = CGRectOffset(self.scrollView.frame, view.frame.size.width * 0, 0);
UIViewController* viewController1=[self.storyboard instantiateViewControllerWithIdentifier:@"navi1"]; ;
UIView* view1 = viewController1.view;
view1.userInteractionEnabled = YES;
view1.frame = self.view.bounds;
view1.frame = CGRectOffset(self.scrollView.frame, view1.frame.size.width * 1, 0);
//加入scrollview中
[self.scrollView addSubview:view];
[self.scrollView addSubview:view1];
//[self.scrollView setContentOffset:CGPointMake(self.scrollView.frame.size.width + self.scrollView.frame.size.width , 0)];
}