【发布时间】:2017-11-27 17:21:50
【问题描述】:
我以编程方式设置按钮如下:-
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
DoctorInfo *docInfo = self.allDoctorInfo[index];
//create new view if no view is available for recycling
if (view == nil)
{
//don’t do anything specific to the index within
//this `if (view == nil) {…}` statement because the view will be
//recycled and used with other index values later
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 200.0f)];
CGFloat centerPoint = (view.frame.size.width / 2) - 25;
((UIImageView *)view).image = [UIImage imageNamed:@"card_shadowed.png"];
view.contentMode = UIViewContentModeCenter;
UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(centerPoint, -30, 50, 50)];
headImage.image = [UIImage imageNamed:@"face.png"];
[view addSubview:headImage];
//share button
UIButton *shareButton = [[UIButton alloc]initWithFrame:CGRectMake(170, -40, 20, 20)];
[shareButton setImage:[UIImage imageNamed:@"share_button.png"] forState:UIControlStateNormal];
[shareButton addTarget:self action:@selector(shareSelected:) forControlEvents:UIControlEventTouchUpInside];
[shareButton.superview setUserInteractionEnabled:YES];
shareButton.clipsToBounds = YES;
[view addSubview:shareButton];
[self.view bringSubviewToFront:shareButton];
return view;
}
在viewdidload中:-
self.carousel.delegate = self;
self.carousel.dataSource = self;
self.carousel.type = iCarouselTypeTimeMachine;
self.carousel.userInteractionEnabled = YES;
我已经尝试了我在谷歌上搜索到的所有建议,但没有一个对我有用。如何使 iCarousel 中的按钮可点击?
【问题讨论】:
-
您尚未在轮播中将
userInteractionEnabled设置为trueviews -
我尝试在 viewforitematindex 中添加 view.userInteractionEnabled = YES 但它仍然无法正常工作@Paulw11
-
您应该尝试在返回视图之前将按钮添加到
if(view == nil)块之外。 -
你可以参考@Nick 本人的这个答案stackoverflow.com/questions/22145978/…
标签: ios objective-c icarousel