문제

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?

도움이 되었습니까?

해결책

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
            }
];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top