Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since your are not posting all of your code here, so I have to guess.</p> <p>Are you creating imageView in <code>onTimer</code> and then trying to move "them" in <code>onTimer2</code>?</p> <p>If YES, then</p> <p>Because you are always setting the <code>imageView</code> var to the latest imageView you created in <code>onTimer</code> method, when you trying move the <code>imageView</code> in <code>onTimer2</code> method, you are only moving the latest one you created.</p> <p>In order to move every imageView you've created, you'd better have a <code>for loop</code> in your <code>onTimer2</code> method.</p> <p>In additional, you'd better make a NSMutableArray to save all your imageViews, or you can use <code>imageView.tag</code> to get your imageView again without having to create an NSMutableArray and release it later.</p> <p>Here is an example how to use NSMutableArray to save and read all of your imageViews:</p> <p>Add this to your class's <code>.h</code> file:</p> <pre><code>NSMutableArray *views; NSMutableArray *XArray; NSMutableArray *YArray; </code></pre> <p>Edit your <code>.m</code> file:</p> <pre><code>... //Create an array some where in your class: views = [[NSMutableArray array] retain]; XArray = [[NSMutableArray array] retain]; YArray = [[NSMutableArray array] retain]; ... - (void)onTimer { [XArray addObject:[NSNumber numberWithFloat:(240.0f - ix)/230.0f]]; [YArray addObject:[NSNumber numberWithFloat:(160.0f - iy)/230.0f]]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]]; [self.view addSubview:imageView]; [views addObject:imageView]; [imageView release]; } //Read: - (void)onTimer2 { for (NSUInteger i = 0; i &lt; [views count]; i++) { UIImageView *imageView = [views objectAtIndex:i]; CGFloat X = [[XArray objectAtIndex:i] floatValue]; CGFloat Y = [[YArray objectAtIndex:i] floatValue]; CGPointMake(imageView.center.x + X, imageView.center.y + Y); } } - (void)dealloc { ... [views release]; [XArray release]; [YArray release]; ... } </code></pre> <p>Or you can use <code>imageView.tag</code> like this:</p> <p>Add this to your class's <code>.h</code> file:</p> <pre><code>NSInteger imageViewCount; </code></pre> <p>Edit your <code>.m</code> file:</p> <pre><code>... #define kImageViewFirstTag 10000 ... ... //reset the count some where in your class if needed imageViewCount = 0; ... - (void)onTimer { UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]]; [self.view addSubview:imageView]; [views addObject:imageView]; imageView.tag = kImageViewFirstTag + imageViewCount; imageViewCount ++; [imageView release]; } //Read: - (void)onTimer2 { for (NSUInteger i = 0; i &lt; imageViewCount; i++) { UIImageView *imageView = (UIImageView *)[self.view viewWithTag:kImageViewFirstTag + i]; CGPointMake(imageView.center.x + X, imageView.center.y + Y); } } </code></pre> <p>The two code are compiled by brain, correct me if there is any mistype.</p> <p><strong>The first way is recommended, because it has better performance.</strong></p>
 

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