我是iOS应用程序开发的新手。我正在创建一个应用程序,我想在scrollview上显示自定义视图并在scrollview上添加视图,但它从第一个视图显示视图。我可以先得到第二个观点。
scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,80,320,360)];
[scrollview setContentSize:CGSizeMake(2550,360)];
[scrollview setScrollEnabled:YES];
[scrollview setPagingEnabled:YES];
[scrollview setBackgroundColor:[UIColor clearColor]];
scrollview .indicatorStyle = UIScrollViewIndicatorStyleDefault;
scrollview.showsHorizontalScrollIndicator = NO;
scrollview.showsVerticalScrollIndicator = NO;
scrollview.scrollsToTop = NO;
scrollview.delegate = self;
scrollview.tag=500;
[self.view addSubview:scrollview];
afterloginPageControl=[[UIPageControl alloc]initWithFrame:CGRectMake(0, 440, 320, 25)];
afterloginPageControl.numberOfPages = 8;
afterloginPageControl.backgroundColor = [UIColor darkGrayColor];
afterloginPageControl.highlighted = YES;
afterloginPageControl.hidesForSinglePage = YES;
afterloginPageControl.currentPage = 0;
afterloginPageControl.selected = YES;
[afterloginPageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventTouchUpInside];
// create Pages..
//[self createPages];
// add View
[self.view addSubview:afterloginPageControl];
info=[[InfoView alloc]initWithFrame:CGRectMake(0, 80,315, 350)];
info.delegate=self;
info.backgroundColor=[UIColor whiteColor];
[scrollview addSubview:info];
update=[[UpdateViewControll alloc]initWithFrame:CGRectMake(320, 80,320, 350)];
update .delegate=self;
update.backgroundColor=[UIColor whiteColor];
[scrollview addSubview:update];
search=[[SearchViewControll alloc]initWithFrame:CGRectMake(640, 80,320, 350)];
//info.delegate=self;
search.backgroundColor=[UIColor whiteColor];
[scrollview addSubview:search];
答案 0 :(得分:4)
在viewDidLoad
中的scrollview上添加视图后使用此代码。
[scrollview scrollRectToVisible:CGRectMake(320, 80,320, 350) animated:YES];