我想使用 UIanimationtransitioncurl 向左或向右使用动画到 imageview。是否可以?
我想让我的照片库像书页一样充满活力。 有什么方法可以在左侧或右侧使用 UIanimationtransitioncurl 吗?
这是您向我建议的代码。我已经在viewdidload方法上完成了分配。
self.title = @"TransitionsTitle";
// Create the container view which we will use for transition animation (centered horizontally).
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0),
kTopPlacement, kImageWidth, kImageHeight);
self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease];
[self.view addSubview:self.containerView];
// The container view can represent the images for accessibility.
[self.containerView setIsAccessibilityElement:YES];
[self.containerView setAccessibilityLabel:NSLocalizedString(@"ImagesTitle", @"")];
// Create the initial image view.
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.mainView.image = [UIImage imageNamed:@"scene1.jpg"];
[self.containerView addSubview:self.mainView];
// Create the alternate image view (to transition between).
CGRect imageFrame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.flipToView = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
self.flipToView.image = [UIImage imageNamed:@"scene2.jpg"];
CGAffineTransform rotate=CGAffineTransformMakeRotation(3.14/2);
[containerView setTransform:rotate];
[self.view addSubview:containerView];
rotate=CGAffineTransformMakeRotation(-3.14/2);
[mainView setTransform:rotate];
[self.containerView addSubview:mainView];
[self.mainView addSubview:flipToView];
// 我已将其放在按钮操作事件上。
- (IBAction)flipAction:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:4];
[UIView setAnimationTransition:([self.mainView superview] ?
UIViewAnimationTransitionCurlDown : UIViewAnimationTransitionCurlDown)
forView:self.containerView cache:YES];
if ([flipToView superview])
{
[self.flipToView removeFromSuperview];
[self.containerView addSubview:mainView];
}
else
{
[self.mainView removeFromSuperview];
[self.containerView addSubview:flipToView];
}
[UIView commitAnimations];
}
I want to animate my photo gallery like the pages of the book.
Is there any method with that I can use UIanimationtransitioncurl in either the left or right side?
This is the code as you have suggested to me. I have done the allocation on the viewdidload method.
self.title = @"TransitionsTitle";
// Create the container view which we will use for transition animation (centered horizontally).
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0),
kTopPlacement, kImageWidth, kImageHeight);
self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease];
[self.view addSubview:self.containerView];
// The container view can represent the images for accessibility.
[self.containerView setIsAccessibilityElement:YES];
[self.containerView setAccessibilityLabel:NSLocalizedString(@"ImagesTitle", @"")];
// Create the initial image view.
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.mainView.image = [UIImage imageNamed:@"scene1.jpg"];
[self.containerView addSubview:self.mainView];
// Create the alternate image view (to transition between).
CGRect imageFrame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.flipToView = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
self.flipToView.image = [UIImage imageNamed:@"scene2.jpg"];
CGAffineTransform rotate=CGAffineTransformMakeRotation(3.14/2);
[containerView setTransform:rotate];
[self.view addSubview:containerView];
rotate=CGAffineTransformMakeRotation(-3.14/2);
[mainView setTransform:rotate];
[self.containerView addSubview:mainView];
[self.mainView addSubview:flipToView];
// I have put it on button action event.
- (IBAction)flipAction:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:4];
[UIView setAnimationTransition:([self.mainView superview] ?
UIViewAnimationTransitionCurlDown : UIViewAnimationTransitionCurlDown)
forView:self.containerView cache:YES];
if ([flipToView superview])
{
[self.flipToView removeFromSuperview];
[self.containerView addSubview:mainView];
}
else
{
[self.mainView removeFromSuperview];
[self.containerView addSubview:flipToView];
}
[UIView commitAnimations];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以。这是我使用的代码,
然后将过渡应用到父视图,
当您上下卷曲时它会向左或向右卷曲。
**请注意,您需要调整视图的偏移量才能使其正确显示,
但这对我来说很有用。
Yes, you can. This is the code I use for that,
And then apply the transition to the parent view,
It will curl to the left or the right when you curl up and down.
**Note that you will need to play with the offset of the views to make it display correctly,
but it works great for me.