Ios5 UIButton ImageView在iCarousel中占用更多空间且不响应触摸事件

Ios5 UIButton ImageView在iCarousel中占用更多空间且不响应触摸事件,ios5,uiimageview,uibutton,icarousel,Ios5,Uiimageview,Uibutton,Icarousel,我是一个初学者,试图用iCarousel制作菜单。到目前为止,我尝试的是为carousel中的每个视图返回一个带有自定义图像的UIButton。图像列表的声明与示例中所述的相同。我面临的问题有: 转盘中返回的按钮视图-其图像未正确调整,如图所示 你们也可以看到,当我展示熊的时候,它正在挑选老虎的描述 当我点击任何图片时,它只是向前滚动,而不是对按钮触碰事件做出反应 -idinitWithNibName:NSString*nibNameOrNil包:NSBundle*nibBundleOrNil

我是一个初学者,试图用iCarousel制作菜单。到目前为止,我尝试的是为carousel中的每个视图返回一个带有自定义图像的UIButton。图像列表的声明与示例中所述的相同。我面临的问题有:

转盘中返回的按钮视图-其图像未正确调整,如图所示

你们也可以看到,当我展示熊的时候,它正在挑选老虎的描述

当我点击任何图片时,它只是向前滚动,而不是对按钮触碰事件做出反应

-idinitWithNibName:NSString*nibNameOrNil包:NSBundle*nibBundleOrNil { self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 如果自我{ //设置传送带数据 包装=是; self.menuItems=[NSMutableArray arrayWithObjects:@Bear.png, @Zebra.png, @Tiger.png, @Goat.png, @Birds.png, @Giraffe.png, 零]; self.descriptions=[NSMutableArray arrayWithObjects:@Bears Eat:Honey, @斑马吃:草, @老虎吃:肉, @山羊吃野草, @鸟吃:种子, @长颈鹿吃:树, 零]; } 回归自我; } -voidbuttonTapped:UIButton*发送方 { NSInteger索引=[aCarousel IndexofitemViewor子视图:发送方]; 开关指数{ 案例0: NSLog@at索引:%d,索引; 打破 案例1: NSLog@at索引:%d,索引; 打破 案例2: NSLog@at索引:%d,索引; 打破 案例3: NSLog@at索引:%d,索引; 打破 案例4: NSLog@at索引:%d,索引; 打破 案例5: NSLog@at索引:%d,索引; 打破 } } -空隙率 { aCarousel.type=IcarousEltypeInverterDropary; aCarousel.delegate=self; aCarousel.dataSource=self; //aCarousel.frame=CGRectMake0,68320257; [超级视图下载]; } 布拉格语-马克·伊卡鲁塞尔代表 -NSU项目整数旋转木马:iCarousel*旋转木马 { 返回[self.menuItems count]; } -NSU转盘中可见项目的整数:iCarousel*转盘 { //限制为提高性能而同时加载的项目视图的数量 返回4; } -UIView*旋转木马:iCarousel*项目旋转木马视图索引:NSUIntegerindex重用视图:UIView*视图 { UIButton*button=[UIButton button类型:UIButtonTypeCustom]; button.bounds=CGRectMake0,0,240.0f,200.0f; [按钮设置图像:[UIImage ImageName:[menuItems objectAtIndex:index]]用于状态:UIControlStateNormal]; [按钮添加目标:自我操作:@selectorbuttonTapped:forControlEvents:uicontrol事件触地]; button.imageView.contentMode=UIViewContentModeScaleAspectFit; button.contentHorizontalAlignment=uicontrolContentHorizontalAlignment填充; //button.contentVerticalAlignment=uicontrol内容垂直对齐填充; 返回按钮; } -NsuIntegerNumber of PlaceHoldersInCarousel:iCarousel*转盘 { 返回0; } -CGFloatcarouselItemWidth:iCarousel*旋转木马 { //通常,这应该比项目视图略宽 返回240;//对于220像素的图像 } -BOOLCAURELSHOULDWRAP:iCarousel*旋转木马 { 返回self.wrap; } -voidCarousedScroll:iCarousel*旋转木马 { [label setText:[NSString stringWithFormat:@%@[descriptions objectAtIndex:carousel.currentItemIndex]]; }
我真的厌倦了几个小时来调整旋转木马。虽然我尝试了aspectfitratio,调整框架,但不知道为什么输出是错误的。有人能找出我哪里做错了吗?非常感谢:

至少我能自己解决这个问题。我不知道为什么我的项目表现得如此奇怪,所以我决定在新项目中使用iCarousel。我注意到的错误如下:

在nib文件中,当我为子视图的iCarousel创建类类型时,它显示了类似于我在对象列表中旋转的内容-我手动将列表中的名称更改为我的iBarousel对象作为aCarousel

其次,我没有在-UIView*carousel:iCarousel*carousel viewForItemAtIndex:nsuiintegerindex reusingView:UIView*视图方法中将UIButton正确分配给UIView。我很高兴在示例文件夹中找到了按钮演示。从那里我复制了我的代码,现在一切都很好

为希望看到以下内容的任何人复制此处的代码:

-UIView*旋转木马:iCarousel*项目旋转木马视图索引:NSUIntegerindex重用视图:UIView*视图 { UIButton*按钮=UIButton*视图; 如果按钮==nil { //没有可回收的按钮,因此创建一个新按钮 UIImage*image=[UIImage ImageName:[menuItems对象索引:索引]]; button=[UIButton按钮类型:UIButtonTypeCustom]; button.frame=CGRectMake0.0f,0.0f,image.size.width,image.size.height; //[按钮设置标题颜色:[UIColor blackColor]用于状态:UICo [正常]; [按钮设置背景图像:状态图像:uicontrol状态正常]; //button.titleLabel.font=[button.titleLabel.font fontWithSize:50]; [按钮添加目标:自我操作:@selectorbuttonTapped:forControlEvents:uicontrol事件触地]; } //设置按钮标签 //[按钮集标题:[NSString stringWithFormat:@%i,索引]用于状态:UIControlStateNormal]; //如果要在按钮上显示一些文本,请使用这些注释行 返回按钮; }