I want to use animation to imageview using UIanimationtransitioncurl right or left. Is it possible?(我想使用 UIanimationtransitioncurl 向右或向左使用动画到 imageview.是否可以?)
问题描述
我想像书页一样为我的照片库设置动画.有什么方法可以让我在左侧或右侧使用 UIanimationtransitioncurl 吗?
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?
这是您向我建议的代码.我已经在viewdidload方法上做了分配.
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];
}
推荐答案
是的,你可以.这是我使用的代码,
Yes, you can. This is the code I use for that,
self.containerViewParent = [[[UIView alloc] initWithFrame:CGRectMake(what ever you want)] autorelease]; //Create a container parent for the container view.
self.containerView = [[[UIView alloc] initWithFrame:GRectMake(what ever you want)] autorelease]; //Create a container view for the view you wish to display.
CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);
[containerViewParent setTransform:rotate]; //Rotate the containerViewParent.
[self.view addSubview:containerViewParent];//Add it to the main view.
rotate = CGAffineTransformMakeRotation(3.14/2);
[containerView setTransform:rotate];//Rotate the containerView.
[self.containerViewParent addSubview:containerView]; //Add it to the self.containerViewParent.
[self.containerView addSubview:viewToDisplay]; //Add the view you want to display.
然后将过渡应用到父视图,
And then apply the transition to the parent view,
[UIView beginAnimations:@"page transition" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.containerView cache:YES];
[UIView commitAnimations];
当你上下卷曲时,它会向左或向右卷曲.
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.
这篇关于我想使用 UIanimationtransitioncurl 向右或向左使用动画到 imageview.是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我想使用 UIanimationtransitioncurl 向右或向左使用动画到 imageview.是否可以?
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01