当前位置:  编程技术>移动开发
本页文章导读:
    ▪从网易资讯看离线阅读的实现思路        从网易新闻看离线阅读的实现思路 原文:http://miloisbadboy.com/archives/157这两天麦洛在做有关离线阅读的功能.关于离线阅读功能思路其实很简单,无非就是先将一些需要的数据下载到本地,当在不需.........
    ▪ UISplitView的简略示例        UISplitView的简单示例 以前写了一篇文章:UISplitView的简单示例,这篇文章实现的功能类似,具体的实现请参考附件。   SplitViewTestAppDelegate.h   #import <UIKit/UIKit.h> @class RootViewController; @class .........
    ▪ 相仿Chome的翻转效果       类似Chome的翻转效果 简单的demo,屏幕上下滑动翻转View,类似Android Chrome的效果       代码很简单,扩展一X轴旋转的动画RotateAnimationEX: package com.ray.animation; import android.graphics.Camera; import .........

[1]从网易资讯看离线阅读的实现思路
    来源: 互联网  发布时间: 2014-02-18
从网易新闻看离线阅读的实现思路

原文:
http://miloisbadboy.com/archives/157

这两天麦洛在做有关离线阅读的功能.

关于离线阅读功能思路其实很简单,无非就是先将一些需要的数据下载到本地,当在不需要网络的时候,可以从本地读取内容.

麦洛看了一下网易新闻的功能(当然具体实现麦洛也是不知道,只是从黑盒子里看看,麦洛自己的一些关于可能实现方式的想法,纯属学习).

阅读更多:
http://miloisbadboy.com/archives/157

    
[2] UISplitView的简略示例
    来源: 互联网  发布时间: 2014-02-18
UISplitView的简单示例

以前写了一篇文章:UISplitView的简单示例,这篇文章实现的功能类似,具体的实现请参考附件。

 

SplitViewTestAppDelegate.h

 

#import <UIKit/UIKit.h>

@class RootViewController;
@class DetailViewController;

@interface SplitViewTestAppDelegate : NSObject <UIApplicationDelegate> {    
    UIWindow *window;
    UISplitViewController *splitViewController;    
    RootViewController *rootViewController;
    DetailViewController *detailViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UISplitViewController *splitViewController;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;

@end

 

SplitViewTestAppDelegate.m

 

#import "SplitViewTestAppDelegate.h"
#import "RootViewController.h"
#import "DetailViewController.h"

@implementation SplitViewTestAppDelegate

@synthesize window, splitViewController, rootViewController, detailViewController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [window addSubview:splitViewController.view];
    [window makeKeyAndVisible];
    
    return YES;
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
    [splitViewController release];
    [window release];
    [super dealloc];
}

@end

 

RootViewController.h

 

#import <UIKit/UIKit.h>

@class DetailViewController;

@interface RootViewController : UITableViewController {
    DetailViewController *detailViewController;
    NSMutableArray *fruits;
}

@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
@property (nonatomic, retain) NSMutableArray *fruits;

@end

 

RootViewController.m

 

#import "RootViewController.h"
#import "DetailViewController.h"

@implementation RootViewController

@synthesize detailViewController;
@synthesize fruits;

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"List of Fruits";
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
	self.fruits = [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"fruits" ofType:@"plist"]] retain];
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    return [fruits count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    
    static NSString *CellIdentifier = @"CellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    cell.textLabel.text = [self.fruits objectAtIndex:indexPath.row];
    return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    detailViewController.detailItem = [self.fruits objectAtIndex:indexPath.row];
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
	[self.fruits release];
    [detailViewController release];
    [super dealloc];
}

@end

 

DetailViewController.h

 

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate> {
    
    UIPopoverController *popoverController;
    UINavigationBar *navigationBar;
    
    id detailItem;
    UILabel *detailDescriptionLabel;
	
	IBOutlet UIImageView *fruitImageView;
}

@property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar;
@property (nonatomic, retain) id detailItem;
@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;
@property (nonatomic, retain) IBOutlet UIImageView *fruitImageView;

@end

 

DetailViewController.m

 

#import "DetailViewController.h"
#import "RootViewController.h"

@interface DetailViewController ()
@property (nonatomic, retain) UIPopoverController *popoverController;
- (void)configureView;
@end

@implementation DetailViewController

@synthesize navigationBar, popoverController, detailItem, detailDescriptionLabel, fruitImageView;

#pragma mark -
#pragma mark Managing the detail item

- (void)setDetailItem:(id)newDetailItem {
    if (detailItem != newDetailItem) {
        [detailItem release];
        detailItem = [newDetailItem retain];
        
		navigationBar.topItem.title = detailItem;
		
		NSString *imageName = [NSString stringWithFormat:@"%@.png", detailItem];
		[self.fruitImageView setImage:[UIImage imageNamed:imageName]];

        [self configureView];
    }

    if (popoverController != nil) {
        [popoverController dismissPopoverAnimated:YES];
    }        
}

- (void)configureView {
    detailDescriptionLabel.text = [detailItem description];   
}

#pragma mark -
#pragma mark Split view support

- (void)splitViewController: (UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem forPopoverController: (UIPopoverController*)pc {    
    barButtonItem.title = @"Master List";
    [navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.popoverController = pc;
}

- (void)splitViewController: (UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
    [navigationBar.topItem setLeftBarButtonItem:nil animated:YES];
    self.popoverController = nil;
}

- (void)viewDidUnload {
    self.popoverController = nil;
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
    [popoverController release];
    [navigationBar release];
    [detailItem release];
    [detailDescriptionLabel release];
    [super dealloc];
}

@end

 

效果图:



    
[3] 相仿Chome的翻转效果
    来源: 互联网  发布时间: 2014-02-18
类似Chome的翻转效果

简单的demo,屏幕上下滑动翻转View,类似Android Chrome的效果

 

 

 

代码很简单,扩展一X轴旋转的动画RotateAnimationEX:

package com.ray.animation;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.Transformation;

public class RotateAnimationEX extends Animation {

	private float mFromDegress, mToDegress;
	private float mCenterX, mCenterY;
	private Camera mCamera;
	private OnFlipListener mFlipListener;
	private boolean onFilpped;
	public RotateAnimationEX(float fromDegrees, float toDegrees, int centerX, int centerY) {
		mFromDegress = fromDegrees;
		mToDegress = toDegrees;
		mCenterX = centerX;
		mCenterY = centerY;
		mCamera = new Camera();
		onFilpped = false;
	}
	
	public void setFlipListener(OnFlipListener listener) {
		mFlipListener = listener;
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		mCamera.save();
		float rotateAngle = mFromDegress + (mToDegress - mFromDegress)*interpolatedTime;
		Log.d("Trace", "angel" + rotateAngle);
		if (mFlipListener != null) {
			if (rotateAngle >= 90 && rotateAngle <=180
			|| rotateAngle <=-90 && rotateAngle >= -180) {
				if (!onFilpped) {
					mFlipListener.onFlip();
					onFilpped = true;
				}
			} 
		}
		mCamera.rotateX(rotateAngle);
		Matrix m = t.getMatrix();
		mCamera.getMatrix(m);
		m.preTranslate(-mCenterX, -mCenterY);
		m.postTranslate(mCenterX, mCenterY);
		mCamera.restore();
	}
	
	public interface OnFlipListener {
		void onFlip();
	}
}
 

一测试的ViewGroup:

package com.ray.animation;

import com.ray.animation.RotateAnimationEX.OnFlipListener;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Color;
import android.graphics.Matrix;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Transformation;

public class TestViewGroup extends ViewGroup implements GestureDetector.OnGestureListener,
	OnFlipListener {

	public static final int MARGIN = 30;
	public static final int MAX_ROTATE_ANGLE = 90;
	private View mTestView;
	private RotateAnimationEX mRotaAnim;
	private GestureDetector mGestureDetector;
	private float rotateAngle = 0;
	private Camera mCamera;
	public TestViewGroup(Context context) {
		super(context);
		mTestView = new View(context);
		mTestView.setBackgroundColor(COLORS[0]);
		addView(mTestView);
		setStaticTransformationsEnabled(true);
		mGestureDetector = new GestureDetector(context,this);
		mCamera = new Camera();
	}
	
	@Override
	protected boolean getChildStaticTransformation(View child, Transformation t) {
		if (child == mTestView) {
			mCamera.save();
			Matrix m = t.getMatrix();
			mCamera.rotateX(rotateAngle);
			mCamera.getMatrix(m);
			m.preTranslate(-child.getWidth() / 2, -child.getHeight() / 2);
			m.postTranslate(child.getWidth() / 2, child.getHeight() / 2);
			mCamera.restore();
			return true;
		}
		return false;
	}



	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b) {
		mTestView.layout(l + MARGIN, t + MARGIN, r - MARGIN, b - MARGIN);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		
		boolean retValue = mGestureDetector.onTouchEvent(event);
		
		if (event.getAction() == MotionEvent.ACTION_UP) {
			mRotaAnim = new RotateAnimationEX(rotateAngle, 180*rotateAngle/Math.abs(rotateAngle),
					mTestView.getWidth()/2, mTestView.getHeight()/2);
			mRotaAnim.setFlipListener(this);
			mRotaAnim.setDuration(700);
			mRotaAnim.setFillAfter(true);
			mTestView.startAnimation(mRotaAnim);
			rotateAngle = 0;
		}
		return retValue;
	}

	@Override
	public boolean onDown(MotionEvent e) {
		if (mTestView != null)
			mTestView.clearAnimation();
		return true;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		rotateAngle = (e1.getY() - e2.getY()) / getHeight() * MAX_ROTATE_ANGLE;
		invalidate();
		return true;
	}

	@Override
	public void onShowPress(MotionEvent e) {	
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}

	@Override
	public void onFlip() {
		mTestView.setBackgroundColor(COLORS[(++mCurrentColor) % COLORS.length]);
	}
	private static int mCurrentColor = 0;
	private static final int[] COLORS = new int[] {Color.BLUE, Color.RED};
}
 

使用代码:

package com.ray.demo;

import com.ray.animation.TestViewGroup;

import android.app.Activity;
import android.os.Bundle;

public class ChromeEggActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new TestViewGroup(this));
    }
}
 

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪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