2013-06-20 215 views
0

是否可以在CGRect屏幕外创建UIImageView?关闭屏幕CGRect

然后,我会在用户按下UIButton之后将它动画到屏幕上。

我知道这个函数CGRectMake(x,y,height, width)但显然x和y不能有负值。

任何人都可以帮助我吗?

+8

x和y的负值是允许的,应该工作正常。为了得到更好的帮助,请解释一下:#1你做了什么(包括确切代码),#2你预期会发生什么,#3实际发生了什么。 –

+3

好奇 - 是什么让你相信x和y的值不能为负? – rmaddy

+0

糟糕,我没有考虑到矩形的宽度,只是从未设置较大的negetave x坐标,感谢您的帮助。我如何关闭这个问题? – bf613

回答

0

是的,这是可能的。有几件事你可以做。根据您希望从中设置动画的位置,将imageview的x和y设置为负数或大于<parentView>.bounds.size.width或高度等。然后,您可以使用UIView对动画进行动画处理。

所以在viewDidAppear或任何方法触发动画您可以使用From apple docs

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

来处理所有的动画。这里是一个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 
      } 
];