ios - 如何让 iCarousel 与 UITableViewController 中的 headerView 一起工作

标签 ios uitableview icarousel

我正在测试如何在 iOS 编程中使用 TableViewController。 我成功地填充了 Controller 的 TableView ,甚至向其中添加了标题 View ,现在我想通过在 View 顶部创建一个可滚动的图片库来使其更有趣。

然后我找到了这个 iCarousel 组件。

我的想法是将 iCarousel 集成到 HeaderView 中,但我没能成功。

我是在正确的轨道上还是我把事情复杂化了?也许我可以试试 UIScrollView?不过我以前没用过。

谢谢大家, 约翰

最佳答案

我已经想出了如何去做。事实上,iCarousel 库在我的案例中可能有点矫枉过正。我只需要在我的表格 View 顶部依次显示一组图像。

这是我做的:

  1. 从界面生成器创建 ImageView ;
  2. 将其 File owner 设置为我的 tableview controller;
  3. 将 tableview controller 的 headView 链接到 image view;
  4. 在 headView 方法中加载 imageView 的 xib 文件;
  5. 将下面的代码添加到 viewDidLoad 方法中:

    UIImageView *imageView = (UIImageView *)self.headerView;

    imageView.animationImages = @[
                                  [UIImage imageNamed:@"image_1"],
                                  [UIImage imageNamed:@"image_2"],
                                  [UIImage imageNamed:@"image_3"],
                                  [UIImage imageNamed:@"image_4"],
                                  [UIImage imageNamed:@"image_5"]
                                  ];
    
    
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.backgroundColor = [UIColor whiteColor];
    imageView.animationDuration = 10;
    [imageView startAnimating];
    
    imageView.isAccessibilityElement = YES;
    imageView.accessibilityLabel = NSLocalizedString(@"Animated", nil);
    

    [self.tableView setTableHeaderView:imageView];

关于ios - 如何让 iCarousel 与 UITableViewController 中的 headerView 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26435489/

相关文章:

ios - 加载 ICarousel 的 MPMovieControl 无法正常工作

ios - Tableview 未加载/触发

objective-c - 如何动态更改 iCarousel 对象的 'wrap' 属性?

ios - 带有 AutoLayout 的 UITableViewCell 中的动态图像高度

ios - 委托(delegate)方法在我的应用程序中工作,我如何使它在我的框架中工作?

ios - 如何在 ios 中更改 UITableView 中一行的位置

ios - UITableView 单元格的阴影在表格滚动后改变位置

iphone - NSMutableArray 难度

iphone - iOS:从另一个 View 将新单元格添加到表格 View

iphone - 无效二进制 : Your binary is not optimized for iPhone 5 As of May 1