iveはicarouselを使用してカバーフロー効果を作成しましたが、xibでプログラムではなく2つのボタンを追加し、アウトレットとアクションを定義してそのボタンに接続しました。しかし、これらのボタンは画像として表示され、機能しません...これが私のコードです.mファイル
@interface GoldViewController ()<UIActionSheetDelegate>
@property (nonatomic, assign) BOOL useButtons;
@end
@implementation GoldViewController
@synthesize carousel1;
-(IBAction)showhome:(id)sender{
ViewController *sec=[[ViewController alloc]initWithNibName:Nil bundle:Nil];
sec.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:sec animated:YES];
}
-(IBAction)showback:(id)sender{
CollectionsViewController *sec=[[CollectionsViewController alloc]initWithNibName:Nil bundle:Nil];
sec.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:sec animated:YES];
}
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
carousel1.type = iCarouselTypeCylinder;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return NUMBER_OF_ITEMS;
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIImage *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@"ban.jpg"],
[UIImage imageNamed:@"pen.jpg"],
[UIImage imageNamed:@"ear1.jpg"],
[UIImage imageNamed:@"neck.jpg"],
[UIImage imageNamed:@"brac.jpg"],
[UIImage imageNamed:@"rings.jpg"],nil];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 250.0f, 320.0f);
[button setImage:(UIImage*)[buttonImage objectAtIndex:index] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;
}
- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
return ITEM_SPACING;
}
- (BOOL)carousel:(iCarousel *)_carousel shouldSelectItemAtIndex:(NSInteger)index
{
if (index == carousel1.currentItemIndex)
{
NSLog(@"Should select current item");
}
else
{
NSLog(@"Should select item number %i", index);
}
return YES;
}
- (void)carousel:(iCarousel *)_carousel didSelectItemAtIndex:(NSInteger)index
{
if (index == carousel1.currentItemIndex)
{
//note, this will only ever happen if useButtons == NO
//otherwise the button intercepts the tap event
NSLog(@"Did select current item");
}
else
{
NSLog(@"Did select item number %i", index);
}
}
@end