0

Is it possible to create UIImageView within a CGRect offscreen?

I will then animate it onto the screen after a user pushes a UIButton.

I know this function CGRectMake(x,y,height, width) but apparently x and y cannot have negative values.

Can anyone help me?

Imane Fateh
  • 2,418
  • 3
  • 19
  • 23
bf613
  • 3
  • 1
  • 8
    Negative values of x and y are allowed and should work fine. To get better help, please explain: #1 what you did (including exact code), #2 what you expected to happen, #3 what actually happened. – Kurt Revis Jun 20 '13 at 18:07
  • 3
    Curious - what led you to believe that the x and y values can't be negative? – rmaddy Jun 20 '13 at 18:10
  • Oops, I didn't take into account the width of my rectangle and just never set a negetave x coordinate that was larger, thanks for you help. How do I close this question? – bf613 Jun 20 '13 at 18:16

1 Answers1

0

Yes it is possible. There are a couple of things that you could do. Depending on where you want it to animate in from, set the x and y of the imageview to be negative or greater than <parentView>.bounds.size.width or height etc. Then you can use UIView to animate changes.

So in viewDidAppear or whatever method triggers the animation you can use From apple docs:

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

to handle all of the animations. Here is an example:

[UIView animateWithDuration:<timeInSecondsOfHowLongItShouldTake>
            animations:^
            {
                    imageView.frame = <CGRectFrameOfPlaceThatYouWantItToGo>
                    //you could also make it fade in with imageView.alpha = 1;
                    //assuming you started out with an alpha < 1
            }
            completion:^(BOOL finished)
            {
                    //do something after it finishes moving 
                    //the imageview into place
            }
];
mrosales
  • 1,543
  • 11
  • 18