UISegmentedControl设置UITableView、页面控件、滚动视图、图像视图

发布于 2024-12-08 10:53:48 字数 1561 浏览 0 评论 0 原文

我有一个带有 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;

    }

}

}

页面控件

部分表格视图

在此处输入图像描述

根据我想做的事情,可能吗?在这个 switch case 函数中?

任何人都可以展示或提供有关如何计算页面控件滑动的教程的任何链接吗?

感谢您阅读

德斯

i have a segmented control with 4 segment

segment 1 - i need a page control to swipe through photos <- -> left & right. 1- 4 photos max

Segment 2 & 3 - i need a table view

Segment 4 - i need it to be able to play video

i'm currently doing this

- (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;

    }

}

}

picture with page control

enter image description here

section tableview

enter image description here

Based on what i will like to do, is it possible ? in this switch case function ?

can anybody show or have any link to tutorial on how to work out the page control swiping ?

thanks for reading

Des

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒七 2024-12-15 10:53:48

我做了一些非常类似的事情,尽管我使用了 UISlider 而不是分段控件 - 你需要的是一个可分页的 UISCrollview,其中有 4 个大小相等的页面(UIViews),如果每页占据 iPhone 的整个宽度为 320,则依次水平加载宽,滚动视图的内容大小宽度将为 1280。绑定 UIsegmented 控件以编程方式滚动页面:

假设页面宽度为 320:

     -(IBAction)movepage:(id)sender {
      int xloc = (segmentedController.selectedSegmentIndex * 320);
      CGRect fieldrect = CGRectMake(xloc,0,320, pagesize.height);

    [scrollView scrollRectToVisible:fieldrect animated:YES];

}

要加载滚动视图和管理页面控制器:

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

}

请注意,您可能需要控制或管理用户滚动滚动视图的能力 - 您可以通过设置滚动视图委托来做到这一点 - 下面的代码不适合您的确切要求,但我相信您可以弄清楚剩下的!

 - (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
 }

I have done something very similar although I used a UISlider instead of segmented control - What you need is a pageable UISCrollview with 4 equal sized pages (UIViews) loaded horizontally one after another if take-up the entire width of an iPhone each page is 320 wide and the content size width of your scrollview will be 1280. Tie up the UIsegmented controls to scroll the pages programatically:

assuming a page width of 320:

     -(IBAction)movepage:(id)sender {
      int xloc = (segmentedController.selectedSegmentIndex * 320);
      CGRect fieldrect = CGRectMake(xloc,0,320, pagesize.height);

    [scrollView scrollRectToVisible:fieldrect animated:YES];

}

To load the scrollview and manage the 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

}

Note you may need to control or manage the user ability to scroll the scroll view - you do that by setting up the scrollview delegate - the code below is not fitted to your exact requirement but I'm sure you can figure out the rest!

 - (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
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文