【问题标题】:How to I add a button on top of iCarousel?如何在 iCarousel 顶部添加按钮?
【发布时间】:2017-08-04 11:16:31
【问题描述】:

我通过代码添加了日期标签和分享按钮。现在我想在右上角添加一个静态按钮来打开一个滑出菜单(我正在使用 MMDrawerController)。如果我添加的是通过代码,它会随着轮播而移动。

如果我在故事板上的名称标签(我的应用程序)上添加一个按钮,它不会被点击,并且正在注册轮播手势而不是按钮点击。

我应该如何继续为右侧的滑出菜单添加一个按钮?

-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{

UIView *magView = nil;

CGFloat height = self.myCarousel.bounds.size.height;
CGFloat width = self.myCarousel.bounds.size.width;

//Magazine View
magView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, width/1.35, height/1.75)];
magView.backgroundColor = [UIColor clearColor];
UIImageView *magImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4 1:2.jpg"]];
magImage.frame = CGRectMake(0, 0, width/1.35, height/1.75);
[magView addSubview:magImage];


//Date Label
UILabel *dateLabel = nil;
dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, height/1.7, width/4, height/25)];
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.text = @"12-03-2017";
dateLabel.font = [UIFont fontWithName:@"Roboto-Black" size:5];
dateLabel.textColor = [UIColor whiteColor];

//Share Button
UIButton *shareButton = nil;
shareButton = [[UIButton alloc] initWithFrame:CGRectMake(width/1.49, height/1.7, height/25, height/25)];
shareButton.backgroundColor = [UIColor clearColor];
[shareButton setBackgroundImage:[UIImage imageNamed:@"share_icon_1x"] forState:UIControlStateNormal];


[magView addSubview:dateLabel];
[magView addSubview:shareButton];

return magView;

}

模拟器

故事板

如何继续添加按钮?

【问题讨论】:

  • 将按钮添加到情节提要并在以编程方式添加轮播之后。添加代码以将按钮置于视图顶部。 [self.view bringSubviewToFront:button].
  • @pawan 我添加了将按钮置于视图顶部的代码,但没有用。即使我在标签上滑动,旋转木马也在移动。也许这就是按钮不起作用的原因
  • 实际上,轮播是在视图顶部添加的。如果您以编程方式添加它,那么就在 [self.view addSubview:carousel]; 之后调用 [self.view bringSubviewToFront:button](确保在调用之前将按钮添加到视图中)
  • 你不能在 icarousel 里面,所以你可以添加按钮,它是 UIVIew 的子视图

标签: ios objective-c icarousel


【解决方案1】:

将按钮添加到情节提要并在以编程方式添加轮播之后。添加代码以将按钮置于视图顶部。

[self.view bringSubviewToFront:button];

如果您以编程方式添加它,那么就在 [self.view addSubview:carousel]; 之后 调用[self.view bringSubviewToFront:button](在调用之前确保按钮已添加到视图中)

【讨论】:

    【解决方案2】:

    我解决了这个问题。我没有查看 ViewController 的视图,而是将另一个视图拖放到 ViewController 上并在其上显示轮播。现在我可以轻松设置按钮了。不过感谢您的帮助。干杯

    【讨论】:

      【解决方案3】:

      它会帮助你

      [xyzButton.superview setUserInteractionEnabled:YES]; 
      

      :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-17
        相关资源
        最近更新 更多