English 中文(简体)
• 如何从横向滚动角度 d弄 mu图象?
原标题:How to drag mutiple images from horizontal scrollview?

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

问题回答

I think a good idea would be to bind all selected images into an NSMutableArray that maintains a reference to them - Add / remove them as they are being selected / deselected respectively. Then, in your "touchesMoved", instead of updating only the UIImageView receiving the touch, iterate over all the selected image views and change their centers as well. Hope this helps!





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签