当前位置:  编程技术>移动开发
本页文章导读:
    ▪uitableview 增添uiview        uitableview 添加uiview [cell.contentView addSubView:subView]; ......
    ▪ UIView转场成效        UIView转场效果 核心功能如代码所示,其他的请参考附件。     FlipTransView.h   #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #define PAGE_VERTICAL_WIDTH 320.0f #define PAGE_VERTI.........
    ▪ 将第三方jar包封装进apk中       将第三方jar包打包进apk中 adt版本为20建立libs文件夹,把第三方jar包放在该文件夹中,想Android Dependencies类路径容器中添加jar包注意文件夹一定要是libs,否则不会出现Android Dependencies类路径.........

[1]uitableview 增添uiview
    来源: 互联网  发布时间: 2014-02-18
uitableview 添加uiview
[cell.contentView addSubView:subView];

    
[2] UIView转场成效
    来源: 互联网  发布时间: 2014-02-18
UIView转场效果

核心功能如代码所示,其他的请参考附件。

 

 

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
 

 示例图:



    
[3] 将第三方jar包封装进apk中
    来源: 互联网  发布时间: 2014-02-18
将第三方jar包打包进apk中
adt版本为20
建立libs文件夹,把第三方jar包放在该文件夹中,想Android Dependencies类路径容器中添加jar包
注意文件夹一定要是libs,否则不会出现Android Dependencies类路径容器

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
c/c++ iis7站长之家
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3