Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 11, 2011, 06:36 PM   #1
xcodeNewbie
macrumors member
 
Join Date: Jul 2011
Help Moving ImageViews

In my app I have an array of image views. I want to move each image in the array up the screen by one pixel at a time. Here's is the code for how I'm trying to do it:
Code:
for (int a=0;a<54;a++) {
        UIImageView *platform = [platformArray objectAtIndex:a];
        platform.center = CGPointMake(platform.center.x,platform.center.y-1);
        [platformArray replaceObjectAtIndex:a withObject:platform]; // Not really sure if this is necessary...
        [platform release];
    }
All of the image views were created and added to my super view in viewDidLoad. However when the program starts all the images are just stationary and never move.
xcodeNewbie is offline   0 Reply With Quote
Old Jul 11, 2011, 06:43 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by xcodeNewbie View Post
Code:
for (int a=0;a<54;a++) {
        UIImageView *platform = [platformArray objectAtIndex:a];
        platform.center = CGPointMake(platform.center.x,platform.center.y-1);
        [platformArray replaceObjectAtIndex:a withObject:platform]; // Not really sure if this is necessary...
        [platform release];
    }
Why are you releasing platform?
__________________
dejo is online now   0 Reply With Quote
Old Jul 11, 2011, 06:46 PM   #3
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Quote:
Originally Posted by xcodeNewbie View Post
In my app I have an array of image views. I want to move each image in the array up the screen by one pixel at a time. Here's is the code for how I'm trying to do it:
Code:
for (int a=0;a<54;a++) {
        UIImageView *platform = [platformArray objectAtIndex:a];
        platform.center = CGPointMake(platform.center.x,platform.center.y-1);
        [platformArray replaceObjectAtIndex:a withObject:platform]; // Not really sure if this is necessary...
        [platform release];
    }
All of the image views were created and added to my super view in viewDidLoad. However when the program starts all the images are just stationary and never move.
First thoughts on this code.

You don't need to replace the object in the array after you change it. objectAtIndex: doesn't return a copy of the object in the array, only a pointer to it. In fact the array doesn't have objects in, it holds pointers to them.

(Re-)read the memory management guide. You do not own the object pointed to by platform because you didn't get the pointer by sending alloc or get, and you haven't retained it. So it's wrong to release it at the end of the loop.
jiminaus is offline   0 Reply With Quote
Old Jul 11, 2011, 09:11 PM   #4
xcodeNewbie
Thread Starter
macrumors member
 
Join Date: Jul 2011
Still Not Working

I tried this code:

Code:
for (int a=0;a<54;a++) {
        UIImageView *platform = [platformArray objectAtIndex:a];
        CGPoint newCenter = CGPointMake(platform.center.x,platform.center.y-1);
        [[platformArray objectAtIndex:a] setCenter:newCenter];
    }
The images still won't move.
xcodeNewbie is offline   0 Reply With Quote
Old Jul 11, 2011, 10:59 PM   #5
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
When, Where, (Why)? is this code being called? Are you even sure that it IS being called? And Why didn't you mention that already?
PhoneyDeveloper is offline   0 Reply With Quote
Old Jul 12, 2011, 11:45 AM   #6
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by xcodeNewbie View Post
I tried this code:

Code:
for (int a=0;a<54;a++) {
        UIImageView *platform = [platformArray objectAtIndex:a];
        CGPoint newCenter = CGPointMake(platform.center.x,platform.center.y-1);
        [[platformArray objectAtIndex:a] setCenter:newCenter];
    }
The images still won't move.
Maybe the problem is in the code you haven't posted.

The way to change that is to post more of your code.
chown33 is offline   0 Reply With Quote
Old Jul 12, 2011, 12:22 PM   #7
RonC
macrumors regular
 
Join Date: Oct 2007
Location: Chicago-area
Quote:
Originally Posted by xcodeNewbie View Post
The images still won't move.
A viewable object (subclass of UIView) is not going to move/update on the screen until a) you tell the view that it needs to redisplay itself (and if you move it, you may need to tell it to re-layout itself), and b) you exit back to the main loop. Your code stays in a loop and moves the center 1 pixel. When does the system get a chance to redisplay/relayout the view, and how will it know it needs to be redisplayed/relayed-out?
RonC is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Moving Harddrives colincarter Mac Pro 6 Dec 9, 2013 05:35 AM
Moving Nicholasdorsey Digital Photography 10 Oct 23, 2013 03:07 PM
iPhone: moving from JB 4S to 5S mtndew Jailbreaks and iOS Hacks 1 Sep 20, 2013 03:07 PM
Moving to 10.7.4 summitRun MacBook Air 4 Jun 19, 2012 01:34 PM
Resolved: FCP - Moving audio and video together when moving into timeline samstah Digital Video 2 Jun 3, 2012 08:22 PM

Forum Jump

All times are GMT -5. The time now is 07:42 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC