0
我有一個圖像視圖作爲子視圖,我試圖實現向上滑動屏幕的手勢。滑動工作,但它不動畫。滑動子視圖關閉屏幕
這是我如何添加子視圖:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
InstagramMedia *media = mediaArray[indexPath.row];
for (int i = 0; i < mediaArray.count; i++)
{
InstagramMedia *instagramMedia = [mediaArray objectAtIndex:i];
[imageArray addObject:instagramMedia.standardResolutionImageURL];
}
largeImageArray = imageArray;
imageIndex = indexPath.row;
UICollectionViewLayoutAttributes *attributes = [self.collectionView layoutAttributesForItemAtIndexPath:indexPath];
CGRect cellRect = attributes.frame;
blurredView = [[UIToolbar alloc]initWithFrame:self.view.bounds];
[blurredView setBarStyle:UIBarStyleBlackOpaque];
[self.view addSubview:blurredView];
imageView = [[UIImageView alloc]initWithFrame:cellRect];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.userInteractionEnabled = YES;
[imageView setImageWithURL:media.standardResolutionImageURL placeholderImage:[UIImage imageNamed:@"placeholder"]];
[self.view addSubview:imageView];
CGRect finalFrame = CGRectMake(0, 50, 320, 301);
[UIView animateWithDuration:0.5 animations:^{
imageView.frame = finalFrame;
}];
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
UISwipeGestureRecognizer *swipeRightRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight:)];
swipeRightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRightRecognizer];
swipeUpRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeUp:)];
swipeUpRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUpRecognizer];
}
這就是我想要做的事:
- (IBAction)swipeUp:(id)sender
{
CGRect finalFrame = CGRectMake(0, -100, 320, 301);
[UIView animateWithDuration:0.5 animations:^{
imageView.frame = finalFrame;
[imageView removeFromSuperview];
[blurredView removeFromSuperview];
[self.view removeGestureRecognizer:swipeUpRecognizer];
}];
}
謝謝!我應該意識到這一點。 – raginggoat
這很酷,但你必須選擇它作爲正確的答案.. :) – Alfa
這讓我等待標記爲正確的答案。我現在已經標記了。再次感謝。 – raginggoat