- 浏览: 2528632 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
jsntghf:
peio 写道这个怎么运行?Ruby On Rails的环境搭 ...
多文件上传之uploadify -
peio:
这个怎么运行?
多文件上传之uploadify -
往事如烟1:
我的项目是自己init了一个原始的project,之后将ver ...
React Native热部署之CodePush -
jsntghf:
往事如烟1 写道我按照你的说明进行,发现app退出之后,在进入 ...
React Native热部署之CodePush -
往事如烟1:
我按照你的说明进行,发现app退出之后,在进入不正确,请问是什 ...
React Native热部署之CodePush
核心功能如代码所示,其他的请参考附件。
FlipTransView.h
#import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #define PAGE_VERTICAL_WIDTH 320.0f #define PAGE_VERTICAL_HEIGHT 480.0f #define PAGE_HORIZONTAL_WIDTH 480.0f #define PAGE_HORIZONTAL_HEIGHT 300.0f @class FlipTransView; @protocol FlipTransViewDelegate <NSObject> @optional - (void)FlipTransViewDidStart:(FlipTransView *)view; - (void)FlipTransViewDidFinish:(FlipTransView *)view; - (void)FlipTransViewDidCancel:(FlipTransView *)view; @end typedef enum { LTOR = 0, RTOL, } TranDirection; @interface FlipTransView : UIView { id<FlipTransViewDelegate> m_pDelegate; @private CALayer *m_pTransformed; UIView *m_pSubView; UIView *m_pNewView; BOOL m_bTransitioning; BOOL m_bEnabled; } @property (nonatomic, retain) UIView *m_pSubView; @property (assign) id<FlipTransViewDelegate> m_pDelegate; @property (readonly, getter = isTransitioning) BOOL m_bTransitioning; - (void)replaceSubviewInCube:(UIView *)aNewView direction:(TranDirection)aDirection duration:(float)aDuration; - (void)replaceSubviewInCube:(UIView *)aNewView direction:(TranDirection)aDirection duration:(float)aDuration isMasked:(BOOL)aIsMasked; @end
FlipTransView.m
#import "FlipTransView.h" #define radians(degrees) degrees * M_PI / 180 #define CUBE_VERTICAL_WIDTH PAGE_VERTICAL_WIDTH #define CUBE_VERTICAL_HEIGHT PAGE_VERTICAL_HEIGHT #define CUBESIZE 320.0f #define MASKALPHA 0.4f #define kAnimationKey @"FlipTransViewAnimation" @implementation FlipTransView @synthesize m_pSubView; @synthesize m_pDelegate; @synthesize m_bTransitioning; - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { m_pSubView = nil; m_bTransitioning = NO; self.backgroundColor = [UIColor clearColor]; } return self; } - (void)addSubview:(UIView *)view { if (view != nil) { self.m_pSubView = view; [super addSubview:view]; } } - (id) captureView:(UIView*)view { UIGraphicsBeginImageContext(view.frame.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), true); UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return (id) [newImage CGImage]; } - (id) captureView:(UIView *)view isMasked:(BOOL)aIsMasked { UIGraphicsBeginImageContext(view.frame.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), true); if (aIsMasked) { CGContextSetRGBFillColor (UIGraphicsGetCurrentContext(), 0, 0, 0, MASKALPHA); CGContextFillRect (UIGraphicsGetCurrentContext(), view.frame); } UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return (id) [newImage CGImage]; } - (CALayer*) makeSurface:(CATransform3D)t withView:(UIView *)aNewView isMasked:(BOOL)aIsMasked { CGRect rect = CGRectMake(0, 0, CUBE_VERTICAL_WIDTH, CUBE_VERTICAL_HEIGHT); CALayer *imageLayer = [CALayer layer]; imageLayer.anchorPoint = CGPointMake(1, 1); imageLayer.frame = rect; imageLayer.transform = t; imageLayer.contents = [self captureView:aNewView isMasked:aIsMasked]; return imageLayer; } - (void)constuctRotateLayer:(UIView *)aNewView direction:(TranDirection)aDirection isMasked:(BOOL)aIsMasked { //init transformed Layer m_pTransformed = [CALayer layer]; m_pTransformed.frame = self.bounds; m_pTransformed.anchorPoint = CGPointMake(0.5f, 0.5f); CATransform3D sublayerTransform = CATransform3DIdentity; /* Set perspective */ sublayerTransform.m34 = 1.0 / -1000; [m_pTransformed setSublayerTransform:sublayerTransform]; [self.layer addSublayer:m_pTransformed]; //init Sublayers CATransform3D t = CATransform3DMakeTranslation(0, 0, 0); [m_pTransformed addSublayer:[self makeSurface:t withView:m_pSubView isMasked:aIsMasked]]; [m_pSubView setHidden:YES]; t = CATransform3DMakeTranslation(0, 0, 0); t = CATransform3DTranslate(t, 320, 0, 0); t = CATransform3DRotate(t, radians(90), 0, 1, 0); CGRect rect = CGRectMake(0, 0, 40, 480); CALayer *imageLayer = [CALayer layer]; imageLayer.anchorPoint = CGPointMake(0, 0); imageLayer.frame = rect; imageLayer.transform = t; CGImageRef subimage=CGImageCreateWithImageInRect([UIImage imageNamed:@"green_bg_home.png"].CGImage, rect); CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), true); imageLayer.contents=(id)subimage; CFRelease(subimage); [m_pTransformed addSublayer:imageLayer]; t = CATransform3DMakeTranslation(0, 0, 0); t = CATransform3DTranslate(t, 0, 0, -40); t = CATransform3DRotate(t, radians(180), 0, 1, 0); rect = CGRectMake(0, 0, 320, 480); imageLayer = [CALayer layer]; imageLayer.anchorPoint = CGPointMake(0.5, 0.5); imageLayer.frame = rect; imageLayer.transform = t; imageLayer.contents = [self captureView:aNewView isMasked:aIsMasked]; [m_pTransformed addSublayer:imageLayer]; } - (void)destroyRotateLayer { [m_pTransformed removeFromSuperlayer]; } - (void)moveFrom:(TranDirection)aDirection duration:(float)aDuration { [CATransaction flush]; CABasicAnimation *rotation; CABasicAnimation *translationX; CABasicAnimation *translationZ; CAAnimationGroup *group = [CAAnimationGroup animation]; group.delegate = self; group.duration = aDuration; translationX = [CABasicAnimation animationWithKeyPath:@"sublayerTransform.translation.x"]; translationX.toValue = [NSNumber numberWithFloat:0.0]; rotation = [CABasicAnimation animationWithKeyPath:@"sublayerTransform.rotation.y"]; rotation.toValue = [NSNumber numberWithFloat:radians(-180)]; translationZ = [CABasicAnimation animationWithKeyPath:@"sublayerTransform.translation.z"]; translationZ.toValue = [NSNumber numberWithFloat:0.0]; group.animations = [NSArray arrayWithObjects: rotation, nil]; group.fillMode = kCAFillModeForwards; group.removedOnCompletion = NO; [m_pTransformed addAnimation:group forKey:kAnimationKey]; } - (void)replaceSubviewInCube:(UIView *)aNewView direction:(TranDirection)aDirection duration:(float)aDuration { [self replaceSubviewInCube:aNewView direction:aDirection duration:aDuration isMasked:NO]; } - (void)replaceSubviewInCube:(UIView *)aNewView direction:(TranDirection)aDirection duration:(float)aDuration isMasked:(BOOL)aIsMasked { // If a transition is in progress, do nothing if(m_bTransitioning || aNewView == nil) return; //If there's a new view and it doesn't already have a superview, insert it where the old view was if (m_pSubView == nil) { [self addSubview:aNewView]; return; } if ([aNewView superview] != nil) { [aNewView removeFromSuperview]; } m_pNewView = aNewView; [self constuctRotateLayer:aNewView direction:aDirection isMasked:NO]; [self moveFrom:aDirection duration:aDuration]; } // Not used in this example, but may be useful in your own project - (void)cancelTransition { // Remove the animation -- cleanup performed in animationDidStop:finished: [[self layer] removeAnimationForKey:kAnimationKey]; } - (void)animationDidStart:(CAAnimation *)animation { m_bTransitioning = YES; [m_pSubView removeFromSuperview]; [m_pSubView setHidden:NO]; // Record the current value of userInteractionEnabled so it can be reset in animationDidStop:finished: m_bEnabled = self.userInteractionEnabled; // If user interaction is not already disabled, disable it for the duration of the animation if (m_bEnabled) { self.userInteractionEnabled = NO; } // Inform the delegate if the delegate implements the corresponding method if(m_pDelegate != nil && [m_pDelegate respondsToSelector:@selector(FlipTransViewDidStart:)]) { [m_pDelegate FlipTransViewDidStart:self]; } } - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished { m_bTransitioning = NO; [self addSubview:m_pNewView]; [self destroyRotateLayer]; m_pNewView = nil; // Reset the original value of userInteractionEnabled if (m_bEnabled) { self.userInteractionEnabled = YES; } // Inform the delegate if it implements the corresponding method if (finished) { if (m_pDelegate != nil && [m_pDelegate respondsToSelector:@selector(FlipTransViewDidFinish:)]) { [m_pDelegate FlipTransViewDidFinish:self]; } } else { if (m_pDelegate != nil && [m_pDelegate respondsToSelector:@selector(FlipTransViewDidCancel:)]) { [m_pDelegate FlipTransViewDidCancel:self]; } } } - (void)dealloc { [m_pSubView release]; [super dealloc]; } @end
示例图:
- FlipTrans.zip (1.6 MB)
- 下载次数: 21
发表评论
-
Error watching file for changes: EMFILE
2016-12-15 11:57 1299执行npm start后报错: Error watc ... -
CocoaPods升级1.1.1报错
2016-12-15 08:39 793ERROR: While executing gem .. ... -
Visual Studio Code运行React Native报错
2016-06-13 09:43 1612React Native:0.27.2 React:15 ... -
React Native 0.27.2编译报错this._nativeModule.addListener is not a function
2016-06-12 15:21 3854React Native:0.27.2 React:15 ... -
Unable to resolve module ReactDefaultPerf from
2016-06-02 13:04 2782package.json信息如下: "reac ... -
React Native 0.26.2编译报错Undefined symbols for architecture x86_64
2016-05-26 11:15 2014React Native:0.26.2 React:15. ... -
Failed to update auto layout status: Failed to load designables from path (null)
2016-04-05 22:11 1714确保CocoaPods是0.36.1以上版本,然后在podf ... -
集成微信支付出现Undefined symbols for architecture x86_64错误
2016-03-21 13:22 1751Undefined symbols for architec ... -
React Native热部署之CodePush
2016-01-10 22:27 6240本文使用的环境是Mac OS 10.11.1、Xcode ... -
浅谈React Native中的FlexBox布局
2015-11-17 18:38 4304React Native通过一个基于FlexBox的布局引 ... -
React Native之构建一个简单的列表页
2015-10-23 14:45 2160本文中我们将创建一个简单的电影应用,这个应用将从Rotten ... -
React Native之环境搭建
2015-10-20 16:30 1445本文使用的环境是Mac O ... -
获取图片属性的方法
2015-10-18 20:43 3143很多时候我们需要获 ... -
NSCache的下标用法
2015-09-18 00:19 1213NSCache类和NSDictionary类很相似,也提供 ... -
如何给category添加属性
2015-08-16 10:41 691主要是使用了runtime中的associative机制。 ... -
UITableView的两种重用Cell方法的区别
2015-08-10 13:07 16145UITableView中有两种重用Cell的方法: - ... -
SDImageCache.m报错Unused variable 'fileName'
2015-08-04 21:56 1172GCC手册中的相关解释: unused:This att ... -
Swift调用Objective-C
2015-07-13 23:33 1226Swift调用Objective-C需要一个名为<工程 ... -
使用GCD实现倒计时
2015-07-24 21:47 1084__block int timeout = 60; // ... -
导航栏加分割线的实现
2015-07-01 22:00 1763self.view.backgroundColor = [U ...
相关推荐
CAAnimation的子类,用于做转场动画,能够为层提供移出屏幕和移入屏幕的动画效果。iOS比Mac OS X的转场动画效果少一点 UINavigationController就是通过CATransition实现了将控制器的视图推入屏幕的动画效果 属性解析...
在iOS开发中,自定义转场动画是一种提升用户体验的有效手段,它可以让你的应用界面在页面切换时展现出独特的视觉效果。本文将深入探讨自定义转场动画的相关知识点,帮助开发者更好地理解和应用这一技术。 首先,转...
在Swift中,我们通常会使用UIView动画来实现转场效果。UIView动画提供了简单的API来创建平滑的动画,包括淡入淡出、缩放、旋转等。结合遮罩技术,我们可以在动画过程中改变遮罩的形状或位置,从而实现图片的动态变化...
"转场动画Demo"是一个展示如何在应用中实现平滑、引人入胜的过渡效果的项目。这个Demo可能包含了一个简单的单视图转场动画,旨在帮助开发者理解并应用这类动画到自己的应用中。 转场动画在iOS中的应用广泛,它们...
"一句话搞定圆形扩散转场动画"是一个针对iOS平台的特定动画实现,它旨在通过简洁的代码实现一个具有视觉冲击力的圆形扩散转场效果。 在iOS中,我们可以使用Core Animation或者UIKit提供的动画框架来创建各种动画,...
本项目"ios-照片选择器转场动画.zip"重点展示了如何在照片选择器中实现平滑的转场效果,特别是针对视图动画的运用。 首先,我们要理解转场动画的基本概念。转场动画是指在两个视图之间切换时,通过动画效果来呈现...
本教程将深入探讨如何实现一个“卡片转场效果”,这种效果常见于App Store和其他许多高质量的应用中,例如18Hero5-Card。我们将主要关注iOS中的多媒体和动画技术,以及如何通过代码来创建类似的效果。 首先,我们要...
在iOS开发中,自定义UIView的阴影效果是一个常见的需求,它可以为UI元素增添层次感和专业性。在本文中,我们将深入探讨如何实现这个功能,包括设置阴影颜色、阴影偏移、阴影透明度以及阴影半径等关键参数。 首先,...
2. 创建转场:通过设置CATransition的type和subtype属性,可以创建不同类型的转场效果。例如,type="kCATransitionFade"表示淡入淡出效果,subtype="kCATransitionFromLeft"表示从左侧推入效果。 3. 设置时长和速度...
除了使用`UIViewControllerTransitioningDelegate`,iOS还提供了一些类方法来快速实现常见的转场效果,例如`UIView.transition(with:duration:options:animations:completion:)`。这个方法可以方便地在两个视图之间...
在iOS开发中,自定义转场动画是一种提升用户体验的有效手段,它可以让你的应用界面在切换页面时展现出独特的视觉效果。这个“ios-自定义转场动画.zip”文件包含了一个名为"CustomTransition(Swift)"的项目,很可能是...
Swift 4 转场动画是iOS应用开发中一种引人注目的视觉效果,它可以增强用户体验,使得页面间的切换更加流畅自然。在Swift 4中,开发者可以利用`UIViewControllerAnimatedTransitioning`和`...
在Swift编程语言中,App Store和Airbnb应用的转场效果是通过自定义视图控制器转场来实现的。这种转场效果不仅提升了用户体验,也增加了应用的视觉吸引力。为了达到这种效果,开发者通常需要对iOS的UIKit框架有深入的...
在iOS应用开发中,上拉转场动画是一种常见的交互效果,用于给用户带来更生动、流畅的界面切换体验。这种动画通常应用于底部弹出新视图或者关闭当前视图的情景,例如显示更多内容、加载数据或展示详情。在本案例中,...
例如,我们可以创建一个扩展,为特定的视图创建匹配的转场效果: ```swift extension YourViewController: UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning { func animation...
首先,SS_AnimationTransition库提供了一个简单易用的接口,使得开发者无需深入了解转场动画的底层实现,就能快速地在应用中添加各种类型的转场效果。这个库具有高内聚、低耦合的特性,降低了对项目原有结构的影响,...
在iOS开发中,实现视图(UIView)或控制器(UIViewController)的缩放动画效果是常见的交互设计,可以增强用户体验并使界面更具动态美感。这里我们将深入探讨如何在iOS应用中创建这种效果,以及如何通过自定义Dome...
当然,你还可以选择其他转场效果,如`.transitionFlipFromLeft`(翻页效果)或`.transitionFlipFromRight`。 如果默认的动画选项无法满足需求,我们可以进一步使用`CATransition`类来自定义更复杂的转场动画。`...
本压缩包文件着重介绍了如何实现一种特殊的转场效果——抽屉效果,同时它还模仿了QQ个人信息页面的转场动画以及App Store中的卡片动画。这些效果为应用程序提供了更加动态和丰富的用户体验。 首先,抽屉效果是iOS...