Note that there are some explanatory texts on larger screens.

plurals
  1. POadd UIImageView on UITapGestureRecognizer and manipulate added UIImageView with other UIGestureRecognizer subclasses
    primarykey
    data
    text
    <p>Might look that I didn't do my homework but I didn't find similar questions.</p> <p>I am creating a <code>UIImageView</code> programmatically when <code>UIView</code> is tapped using <code>UITapGestureRecognizer</code>. Then I want to use/apply other <code>UIGestureRecognizer</code> subclasses on the created <code>UIImageView</code>.</p> <p>What is the best solution to this?</p> <p>NOTE: Current code is working and doing what I but I want avoid calling <code>[self viewDidLoad];</code> from another method(look at pasteImage method).</p> <p>Here is my relevant code</p> <p>.h file</p> <pre><code>@property (retain, nonatomic) IBOutlet UIImageView *imageView; @property (retain, nonatomic) IBOutlet UIImageView *character; @property (retain, nonatomic) IBOutlet UIImage *uiImg; </code></pre> <p>.m file</p> <pre><code>@synthesize character; @synthesize uiImg; - (void)pasteImage:(UITapGestureRecognizer *)t { imageNSArray = [NSMutableArray array]; uiImg = [UIImage imageNamed:@"homer.png"]; CGPoint loc = [t locationInView:self.view]; for (character in imageNSArray) { if ([character pointInside:[character convertPoint:loc fromView:self.imageView] withEvent:nil]) { [imageNSArray removeObject:character]; [character removeFromSuperview]; return; } } character = [[UIImageView alloc] initWithImage:uiImg]; character.center = loc; NSLog(@"self.character value %@",character); [imageNSArray addObject:character]; [self viewDidLoad]; } - (void)viewDidLoad { //Tap gesture UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pasteImage:)]; [self.previewImage addGestureRecognizer:tap]; //Pan gesture character = [[UIImageView alloc]initWithImage:uiImg]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; pan.delegate = self; [character addGestureRecognizer:pan]; [pan setMinimumNumberOfTouches:1]; [pan setMaximumNumberOfTouches:1]; character.center = self.view.center; [self.view addSubview:character]; character.userInteractionEnabled = YES; [tap release]; [pan release]; [super viewDidLoad]; } - (void)handlePan:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInView:self.view]; recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload