0

I couldn't figure out a quick, concise way to explain what I'm trying to accomplish (which has made it difficult to find an answer searching Google), so I'll just try to elaborate more here. What I am trying to accomplish is moving a UIImageView to the top edge of the iPhone's screen and then keep moving it up, but once the image passes the top edge, have it appear at the bottom of the screen, as it continues moving through.

Moving Up enter image description here End

I've been using the basic [UIView commitAnimations] commands for the basic moving of objects in my application, so it'd be nice if this could be accomplished using using that (though it doesn't have to).

iMinichrispy
  • 134
  • 2
  • 14
  • Core Animation isn't built for this stuff. You can fake it with two image views. – CodaFi Jul 01 '13 at 01:09
  • I've done it (horizontal, but same theory), this is *not* fun. look long and hard into other ways around this. – Kevin Jul 01 '13 at 01:13
  • @CodaFi Do you know what *is* built for this? I'm trying to apply this to many different UIImageViews, so I fear using two images for each would complicate things – iMinichrispy Jul 01 '13 at 01:15
  • @Kevin I currently don't have any method of achieving the effect, and it's something I would really like to have in this app – iMinichrispy Jul 01 '13 at 01:16
  • May b this helps u. https://github.com/nicklockwood/SwipeView – iCoder Jul 01 '13 at 06:02

3 Answers3

1

You don't need to mess around with scroll views or switch to cocos2d to implement simple animations. All you need to do is create 2 CALayer objects and then assign layer.contents to the same image.

CALayer *layer1 = [CALayer layer]
CALayer *layer2 = [CALayer layer]
UIImage *image = [UIImage imageNamed:@"whatever.png"];

layer1.contents = (id) image.CGImage;
layer2.contents = (id) image.CGImage;

Then use a normal animation to update the position of the two frames as described this Apple QA doc. You just need to determine the height of the window and then make sure that the start and end Y points of the 2 CALayers are always 1 height of difference. So, when layer1 animates to Y = -1 that means that layer2 would be at Height-1. Only when both layers are partially exposed would you see then both, that is how you get this effect to work and seem to be only 1 layer.

MoDJ
  • 4,309
  • 2
  • 30
  • 65
0

I think you could do this with a UIScrollView... here's something I wrote on cyclic scroll views a while ago.

I would begin by making the content size be the height of the window with the image view at one edge. As the image scrolls off the visible area the next page is coming into view with another image that looks the same but is not. I think this could save you a lot of frame calculations, nested animation blocks and other confusions. You could certainly do it with discrete views but I think it could be reinventing the wheel.

Community
  • 1
  • 1
Adam Eberbach
  • 12,309
  • 6
  • 62
  • 114
0

The best way to implement this is to create a CCNode subclass that will contain first and second sprite and will swap them if required. In this way all your logic will be very simple. You will just work with one CCNode (subclass) and will not think about swaping sprites - it will be done automatically by your class

@interface MyNode : CCNode
{
CCSprite *sprite1;
CCSprite *sprite2;
CCSprite *currentSprite;
bool isChanging; //indicates that now two sprites are visible
}
@end
rezand
  • 576
  • 3
  • 11
  • Never worked with sprites before, I'll look more into it and see if I can get it to work for this – iMinichrispy Jul 01 '13 at 02:05
  • sorry i just usually see the behavior in games, i suppose nothing "game related" is really needed in your programming just tricking the user into thinking they are seeing one object but really creating your own way of a copy as most users have said and i guess once copy is completely on screen then place original image there and remove the copy/mirrored object – rezand Jul 01 '13 at 02:18