i 用户能否从横向浏览中选择图像,如果选择图像,他也应当能够冲破所有选定的图像?
i 能够在某个时候选择一个图像,并能够抹杀单一形象,但想要在另一个图像之后选择一个图像,就应当能够把一个图像推给另一个图像?
我的这部法典:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
imagesName = [[NSArray alloc]initWithObjects:@"hat3.png",@"hat4-1.png",@"t-shirt.png",@"t-shirt.png",
@"Untitled-2.png",@"logo1.jpg",@"logo2.jpg",@"logo3.jpg",nil];
images = [[NSMutableArray alloc]init];
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setMultipleTouchEnabled:YES];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"t-shirt.png"]];
imageView.center = self.view.center;
[self.view addSubview:imageView];
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
int scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);
int xOffset = 0;
imageView.image = [UIImage imageNamed:[imagesName objectAtIndex:0]];
//for(int index=0; index < [imagesName count]; index++)
for (int index=0; index < [imagesName count]; index++)
{
UIImageView *img = [[UIImageView alloc] init];
//img.bounds = CGRectMake(10, 10, 50, 50);a
img.bounds = CGRectMake(0, 0, 20, 20);
//img.frame = CGRectMake(5+xOffset, 0, 160, 110);
img.frame = CGRectMake(0+xOffset, 0, 60, 61);
//img.frame = CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>);
NSLog(@"image: %@",[imagesName objectAtIndex:index]);
img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
[images insertObject:img atIndex:index];
scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110);
[scrollView addSubview:[images objectAtIndex:index]];
xOffset += 170;
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [[event allTouches] anyObject];
for(int index=0;index<[images count];index++)
{
UIImageView *imgView = [images objectAtIndex:index];
NSLog(@"x=%f,y=%f,width =%f,height=%f",imgView.frame.origin.x,imgView.frame.origin.y,imgView.frame.size.width,imgView.frame.size.height);
NSLog(@"x= %f,y=%f",[touch locationInView:self.view].x,[touch locationInView:self.view].y) ;
if(CGRectContainsPoint([imgView frame], [touch locationInView:scrollView]))
{
[self ShowDetailView:imgView];
break;
}
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
NSArray *allTouches = [touches allObjects];
int count = [allTouches count];
if (count == 1) {
if (CGRectContainsPoint([imageView frame], [[allTouches objectAtIndex:0] locationInView:self.view])) {
imageView.center = [[allTouches objectAtIndex:0] locationInView:self.view];
return;
}
}
}
please help suggest me some tutorial