具体的实现是使用QuartzCore库,下面我具体的描述一下实现过程:
- 首先创建一个项目,名字叫:ipad_webwiew
- 利用Interface Builder添加一个UIWebView,然后和相应的代码相关联
- 添加QuartzCore.framework
代码实现:
头文件:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ipad_webwiewViewController : UIViewController {
IBOutlet UIWebView *myWebView;
UIView *myView;
}
@property (nonatomic,retain) UIWebView *myWebView;
@end
代码实现:
- (void)viewDidLoad { [super viewDidLoad]; //给图层添加背景图片: //myView.layer.contents = (id)[UIImage imageNamed:@"view_BG.png"].CGImage; //将图层的边框设置为圆脚 myWebView.layer.cornerRadius = 8; myWebView.layer.masksToBounds = YES; //给图层添加一个有色边框 myWebView.layer.borderWidth = 5; myWebView.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]; }
package com.android.chapter3;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
public class ChapterMain extends Activity
{
private GLSurfaceView mGLSurfaceView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// 实例化GLSurfaceView
mGLSurfaceView = new GLSurfaceView(this);
// 设置渲染器
mGLSurfaceView.setRenderer(new GLRender());
setContentView(mGLSurfaceView);
}
@Override
protected void onResume()
{
super.onResume();
mGLSurfaceView.onResume();
}
@Override
protected void onPause()
{
super.onPause();
mGLSurfaceView.onPause();
}
}
===============================================
package com.android.chapter3;
import java.nio.IntBuffer;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;
public class GLRender implements Renderer
{
int one = 0x10000;
// 用于控制三角形和正方形旋转的角度
float rotateTri, rotateQuad;
//三角形三个顶点
private IntBuffer triggerBuffer = IntBuffer.wrap(new int[]{
0, one,0, //上顶点
-one,-one,0, //左下点
one,-one,0,}); //右下点
//正方形的4个顶点
private IntBuffer quaterBuffer = IntBuffer.wrap(new int[]{
one, one,0,
-one, one,0,
one,-one,0,
-one,-one,0});
//三角形的顶点颜色值(r,g,b,a)
private IntBuffer colorBuffer = IntBuffer.wrap(new int[]{
one, 0, 0,one,
0,one, 0,one,
0, 0,one,one,
});
@Override
public void onDrawFrame(GL10 gl)
{
// TODO Auto-generated method stub
// 首先清理屏幕
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
// 设置模型视图矩阵
gl.glMatrixMode(GL10.GL_MODELVIEW);
//重置矩阵
gl.glLoadIdentity();
// 视点变换
GLU.gluLookAt(gl, 0, 0, 3, 0, 0, 0, 0, 1, 0);
// 设置模型位置
gl.glTranslatef(-3.0f, 0.0f, -4.0f);
//设置旋转(y轴)
gl.glRotatef(rotateTri, 0.0f, 1.0f, 0.0f);
// 允许设置顶点
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
// 允许设置颜色数组
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
//设置颜色数组
gl.glColorPointer(4, GL10.GL_FIXED, 0, colorBuffer);
// 设置三角形的顶点数据
gl.glVertexPointer(3, GL10.GL_FIXED, 0, triggerBuffer);
//放大三角形
gl.glScalef(2.0f, 2.0f, 2.0f);
//绘制三角形
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
//关闭颜色数组的设置
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
/*****正方形*****/
//设置正方形的颜色
gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f);
// 重置当前的模型观察矩阵
gl.glLoadIdentity();
// 设置模型位置
gl.glTranslatef(1.0f, 0.0f, -4.0f);
//设置旋转(x轴)
gl.glRotatef(rotateQuad, 1.0f, 0.0f, 0.0f);
//设置正方形顶点数组
gl.glVertexPointer(3, GL10.GL_FIXED, 0, quaterBuffer);
//绘制正方形
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
/* 绘制出来则是线框 */
//gl.glDrawArrays(GL10.GL_LINES, 0, 4);
// 取消顶点设置
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
//改变旋转的角度
rotateTri += 0.5f;
rotateQuad -= 0.5f;
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
// TODO Auto-generated method stub
float ratio = (float) width / height;
// 设置视口(OpenGL场景的大小)
gl.glViewport(0, 0, width, height);
// 设置投影矩阵为透视投影
gl.glMatrixMode(GL10.GL_PROJECTION);
// 重置投影矩阵(置为单位矩阵)
gl.glLoadIdentity();
//创建一个透视投影矩阵(设置视口大小)
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
// TODO Auto-generated method stub
//告诉系统需要对透视进行修正
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
//设置清理屏幕的颜色
gl.glClearColor(0, 0, 0, 1);
//启用深度缓存
gl.glEnable(GL10.GL_DEPTH_TEST);
}
}
Handler学习小结,算是搞清楚了,得记下来
Handler主要用于异步消息的处理:当发送一个消息之后,首先进入一个消息队列,发送消息的函数即可返回,而另外一个部分逐个的在消息队列中将消息取出,然后对消息进行出来,就是发送消息和接收消息不是同步的处理。这种机制通常用来处理相对好是比较长的操作。(就如post方法是讲Runnable对象添加到主线程中,通俗的说:这里的代码中主要用Handler通知主线程,在主线程中处理异步结果,当线程中耗时任务完成后,例如数据准备,就通知主线程更新(如:更新UI),Handler的hand)
Handler 常用方法:
post(Runnable,long)
postDelayed(Runnable,long);
sendEmptyMessage(int What);
sendMessage(Message);
sendMessageAtTime(Message,long);
sendMessageDelayed(Message,long);
以上post方法允许你安排一个Runnable对象到主线程队列 中,
sendMessage 方法,允许你安排一个带数据的Message对象到队列中,等待更新
package com.handler.test; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class Handler1Activity extends Activity { private Button button = null; private TextView textview = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.button); textview = (TextView) findViewById(R.id.textview); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new Thread(thread).start(); try { Thread.sleep(2000); Log.i("Handler1Activity", "主线程"); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if(msg.what==1){ textview.setText("处理完成"); System.out.println("handler"+Thread.currentThread().getId()); } } }; private Thread thread = new Thread(){ @Override public void run() { //这里处理异步消息 Log.i("Handler1Activity", Thread.currentThread().getId()+"异步处理"); handler.sendEmptyMessage(1); } }; }
这里的
System.out.println("handler"+Thread.currentThread().getId());//handler1