我正在制作一个由旋转木马组成的iPhone应用程序。请任何人都可以告诉我们如何对所选的Carousel图像执行操作。
- (void)carousel:(iCarousel *)crsl didSelectItemAtIndex:(NSInteger)index { }
我正在努力实现这一点,但它没有给出正确的结果,请任何人都能说出正确的实施
感谢
答案 0 :(得分:0)
一旦尝试这样,
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[menuViews objectAtIndex:index]]];
_reflectionView =[[[ReflectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, image.size.width, image.size.height)] autorelease];
UIButton *button = [[[UIButton alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)] autorelease];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:14];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag = index;
[_reflectionView addSubview:button];
return _reflectionView;
}
在上面的代码中,menuViews是图像数组。
- (void)buttonTapped:(UIButton *)sender
{
NSLog(@"%d",sender.tag);//based on tag value you can do whatever you want
}
答案 1 :(得分:0)
像这样设置iCarousel的DataSource和Delegate
而在.h文件中为您的iCarousel设置ViewController代理
#import <UIKit/UIKit.h>
#import "iCarousel.h"
@interface iCarouselViewController : UIViewController<iCarouselDataSource, iCarouselDelegate>
@property (strong, nonatomic) NSMutableArray *images;
@property (nonatomic, retain) IBOutlet iCarousel *carousel;
@end
在.m文件中,像这样编写委托方法didSelectItemAtIndex
-(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index
{
UIImage * img = [images objectAtIndex:index];
ImageViewController *aImageViewController = [[ImageViewController alloc] initWithNibName:@"ImageViewController" bundle:nil];
aImageViewController.image = img; //this code is used to send image to another view not tested
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:aImageViewController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
//this code used for present second-view controller that display selected image
navigationController.topViewController.title = @"Greeting's";
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}