我有4段
的分段控件段1 - 我需要一个页面控件来浏览照片< - - >左和右对。最多1-4张照片
第2段和第2段3 - 我需要一个表格视图
第4段 - 我需要它才能播放视频
我正在做这个
- (IBAction)infoAction:(id)sender {
NSString * selectedTitle = [info titleForSegmentAtIndex:[info selectedSegmentIndex]];
NSLog(@"Selected Title = %@",selectedTitle);//test
switch ([info selectedSegmentIndex])
{ case 0:
{
test.text = [frogInfo.imageFiles objectAtIndex:0];
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:@"Detail1Temp.png"]];
break;
}
case 1:
{
test.text = frogInfo.description;
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:@"Detail2Temp.png"]];
break;
}
case 2:
{
test.text = frogInfo.distribution;
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:@"Detail3Temp.png"]];
break;
}
case 3:
{
test.text = [frogInfo.videoFiles objectAtIndex:0];
test.textColor = [UIColor whiteColor];
[tempImageView setImage:[UIImage imageNamed:@"Detail4Temp.png"]];
break;
}
}
}
带页面控制的图片
section tableview
根据我想做的事情,有可能吗?在这个开关案例功能?
任何人都可以显示或有任何关于如何计算页面控件滑动的教程链接吗?
感谢阅读
德
答案 0 :(得分:0)
虽然我使用了UISlider而不是分段控件,但我做了一些非常相似的事情 - 你需要的是一个可分页的UISCrollview,它有4个相同大小的页面(UIViews)一个接一个地水平加载,如果占用iPhone的整个宽度页面宽度为320,滚动视图的内容大小宽度为1280.绑定UI分段控件以编程方式滚动页面:
假设页面宽度为320:
-(IBAction)movepage:(id)sender {
int xloc = (segmentedController.selectedSegmentIndex * 320);
CGRect fieldrect = CGRectMake(xloc,0,320, pagesize.height);
[scrollView scrollRectToVisible:fieldrect animated:YES];
}
加载scrollview并管理pagecontroller:
pagectrl.numberOfPages = 4;
pagectrl.currentPage = 0;
scrollView.pagingEnabled = YES;
scrollView.contentSize=CGSizeMake(320* pagectrl.numberOfPages, 500);
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.bouncesZoom = NO;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
search_url.delegate = self;
user.delegate = self;
password.delegate = self;
rpc_code.delegate = self;
// add pages
int page = 0;
CGRect frame = scrollView.frame;
pagesize = frame.size.width;
frame.origin.y = 0;
frame.origin.x = frame.size.width * page;
firstView.frame = frame;
[scrollView addSubview:firstView];
page ++;
frame.origin.x = frame.size.width * page;
locsubView.frame = frame;
[scrollView addSubview:locsubView];
page ++;
frame.origin.x = frame.size.width * page;
QRgensubView.frame = frame;
[scrollView addSubview:QRgensubView];
page ++;
frame.origin.x = frame.size.width * page;
scansubView.frame = frame;
[scrollView addSubview:scansubView];
page ++;
frame.origin.x = frame.size.width * page;
symbologysubView.frame = frame;
[scrollView addSubview:symbologysubView];
[self registerForKeyboardNotifications];
CGRect fieldrect = CGRectMake(0,0,320, pagesize);
[scrollView scrollRectToVisible:fieldrect animated:YES]; //goto 1st page
}
注意您可能需要控制或管理用户滚动滚动视图的功能 - 您可以通过设置scrollview委托来执行此操作 - 下面的代码不符合您的确切要求但我相信您可以找出休息!
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// We don't want a "feedback loop" between the UIPageControl and the scroll delegate in
// which a scroll event generated from the user hitting the page control triggers updates from
// the delegate method. We use a boolean to disable the delegate logic when the page control is used.
// if (pageControlUsed)
// {
// do nothing - the scroll was initiated from the page control, not the user dragging
// return;
// }
// Switch the indicator when more than 50% of the previous/next page is visible
int page = floor((scrollView.contentOffset.x - pagesize / 2) / pagesize) + 1;
pagectrl.currentPage = page;
// A possible optimization would be to unload the views+controllers which are no longer visible
}