2014-09-28 207 views
-1

我有UIView,在它的顶部,我有一个UIImageView,在底部UICollectionView。我的观点是,当用户向上滑动手指时,UIImageView框架应该轻轻移出(消失),并且当用户向下滑动时,它应该再次出现(使用移动动画)。以编程方式移动UIImageView框架

实际上,它工作,直到我设置图像到UIImageView。旧代码(下面介绍)没有它工作得很好:

-(void)handleSwipeDown:(UISwipeGestureRecognizer *)recognizer { 

    NSLog(@"Swipe received."); 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 

    self.myCollectionView.frame = CGRectMake(0, 152, 320, 480); 
    [UIView commitAnimations]; 
} 

然后:

-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { 

    NSLog(@"Swipe received."); 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 

    self.myCollectionView.frame=CGRectMake(0, 0, 320, 480); 

    [UIView commitAnimations]; 
} 

后我设置图像:

UIImage *firstImage = [UIImage imageNamed:@"ipd1.jpg"]; 
    self.imageSlideshow.image = firstImage; 

以上代码停止工作。 UIImage框架保持在同一个地方。 我怎么能让它移动? 任何意见,将不胜感激,谢谢!

回答

2

您应该停止使用beginAnimations:context:commitAnimations块。从Apple的文档:

在iOS 4.0及更高版本中不鼓励使用此方法。您应该使用基于块的动画方法来指定您的动画。

使用这个代替:

[UIView animateWithDuration:0.5 animations:^{ 
    self.myCollectionView.frame = CGRectMake(0, 152, 320, 480); 
}]; 

就上述替换整个swipeDown方法。

+0

谢谢,但它不工作,图像仍然在这里。 – 2014-09-28 08:54:59

+0

在代码示例中,您正在移动myCollectionView的框架,但我认为您还需要移动imageSlideshow以及? – believesInSanta 2014-09-28 08:57:09

+0

那么,其实在我的代码imageView是不可见的,但在面对面,它的位置并没有改变。我只是将collectionView的其余部分“拉”起来(因为在屏幕下方,它是隐形的)。 – 2014-09-28 09:03:54

相关问题