ios - How can I change image positions after creating in loop and making them subviews? -


in app have several 'for' loops this:

for (int = 0; <= 100; i++)     {         cmmajormarker = [[uiimageview alloc] initwithimage:image];         cmmajormarker.frame = cgrectmake(0, 0, widthvar,heighvar);         cmmajormarker.center = cgpointmake(xvar,yvar);         [self.scrollview addsubview:cmmajormarker];     } 

(small edit: above code simplified, why appears little)

they want them do, repeat little black marker every number of pixels.

my problem arises when want change position of these markers. want swap side of screen on.

i'm doing in method, thought need write following code change position of 100 images created:

cmmajormarker.center = cgpointmake(xvar2, yvar2); 

i should have realised change position of last of 100 images created, instead of of them.

my question how can change position of 100 images created in loop?

changing loop accommodate solution not problem.

i want avoid removing subviews , recreating them in new position because might suspect, takes time images drawn. removing subviews , recreating them loops takes on second , need lot quicker (and put lot less strain on device).

i'm stumped , desperately need sleep. appreciated.

you create nsmutablearray instance variable hold markers , iterate on them later again:

nsmutablearray *markercontainer = [nsmutablearray new]; 

and change current code to

for (int = 0; <= 100; i++) {     cmmajormarker = [[uiimageview alloc] initwithimage:image];     cmmajormarker.frame = cgrectmake(0, 0, widthvar,heighvar);     cmmajormarker.center = cgpointmake(xvar,yvar);     [self.scrollview addsubview:cmmajormarker];     [markercontainer addobject:cmmajormarker]; } 

if want change center of of them following:

for (uiimageview *marker in markercontainer) {     marker.center = cgpointmake(xvar2, yvar2); } 

note: current code sets all of markers @ exact same position - intended or there more code not showing yet? ;)


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -