Ios 如何在旋转木马中选择图像并转到iPhone中的下一个视图
我正在制作一个iPhone应用程序,其中包括旋转木马。请告诉我们如何对所选的旋转木马图像执行操作Ios 如何在旋转木马中选择图像并转到iPhone中的下一个视图,ios,icarousel,Ios,Icarousel,我正在制作一个iPhone应用程序,其中包括旋转木马。请告诉我们如何对所选的旋转木马图像执行操作 - (void)carousel:(iCarousel *)crsl didSelectItemAtIndex:(NSInteger)index { } 我试图实现这一点,但它没有给出正确的结果,请任何人告诉正确的实现这一点 谢谢像这样尝试一下 - (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)ind
- (void)carousel:(iCarousel *)crsl didSelectItemAtIndex:(NSInteger)index { }
我试图实现这一点,但它没有给出正确的结果,请任何人告诉正确的实现这一点
谢谢像这样尝试一下
- (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是images数组
- (void)buttonTapped:(UIButton *)sender
{
NSLog(@"%d",sender.tag);//based on tag value you can do whatever you want
}
如下设置iCarousel的数据源和委托
-(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];
}
并在.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
您是否设置了iCarousel的数据源和委托?您能否告诉我们,您在选择项目时尝试执行什么操作?转到下一个视图,保存图像等任何我们可以在按钮上执行的操作。在这种情况下,您为什么需要添加按钮。已经为viewSelectionYour welcome提供了委托方法。如果遇到任何问题,请告诉我。我还没有测试过图像传递代码,但是视图代码已经测试过了。。我的意思是默认屏幕显示从手机屏幕中间开始的iCarousel。我想改变它的位置,这样它就可以从手机屏幕开始,希望你明白我的意思