开发者

How to undo the actions of previous touch on UIImageView when touch it again and also how to give preview?

开发者 https://www.devze.com 2023-03-10 12:17 出处:网络
My question is actually simple but for better understanding I explained everything here. I have a series of UIImageView\'s inside a UIScrollView and also have another big UIImageView.

My question is actually simple but for better understanding I explained everything here.

I have a series of UIImageView's inside a UIScrollView and also have another big UIImageView.

My code is like this

- (void)viewDidLoad {   

    imgScrollView.clipsToBounds = YES;      
    imgScrollView.scrollEnabled = YES;
    imgScrollView.userInteractionEnabled =YES;

    // load all the images 
    NSUInteger i;
    for (i = 1; i <= 9; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];

        CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, kHeight, kWidth);

        // TapImage is a subclassed UIImageView that catch touch/tap events 
        TapImage *imageView = [[[TapImage alloc] initWithFrame:imageViewFrame] autorelease];
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:imageName];
        imageView.tag = i;  

        [self.imgScrollView addSubview:imageView];
        [imageView release];
    }

    [self layoutImages];
    [super viewDidLoad];
}

TapImage is a subclassed UIIma开发者_开发知识库geView. code is like this

 @interface TapImage : UIImageView {
 }
 @end


 @implementation TapImage
 - (id)initWithFrame:(CGRect)aRect {
     if (self = [super initWithFrame:aRect]) {
         self.userInteractionEnabled = YES;
     }
     return self;
 }

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {     
     [self.layer setBorderColor: [[UIColor greenColor] CGColor]];
     [self.layer setBorderWidth: 2.0];

     NSLog(@"Touches began %@",touches);    
 }
  1. I want to give preview in big UIImageView, when touching one image in the scroll view ( Just like the 'Film Strip view' feature in Windows OS ). But the problem is, bigPreview UIImageView is not accessible from TapImage class as its not part of the TapImage class. Then whats the solution here??

  2. When touching one image in the scrollView, it gets a green border (indicating as selected). Here, I want to deselect the previously touched image when we touch another image in the scrollView (means, at a time only one image gets selected and previewed ). But the problem is, when touch on it, each UIImageView calls its own touchesBegan: method. Then how to deselect the previously touched image??

Please help me with some simple and detailed answers. :-) Thanx in advance. :-)


This is a perfect example of when to use a delegate method. Essentially, a delegate method allows actions in one viewController (button clicked, view tapped, etc) to trigger the methods of another.

0

精彩评论

暂无评论...
验证码 换一张
取 消