view的ipod touch5会中断吗

wince唤醒后touch中断问题
[问题点数:40分,结帖人devilgavin]
wince唤醒后touch中断问题
[问题点数:40分,结帖人devilgavin]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2012年1月 硬件/嵌入开发大版内专家分月排行榜第二2011年11月 硬件/嵌入开发大版内专家分月排行榜第二2011年10月 硬件/嵌入开发大版内专家分月排行榜第二2011年9月 硬件/嵌入开发大版内专家分月排行榜第二
2012年3月 硬件/嵌入开发大版内专家分月排行榜第三2012年2月 硬件/嵌入开发大版内专家分月排行榜第三
2014年10月 硬件/嵌入开发大版内专家分月排行榜第二2014年2月 硬件/嵌入开发大版内专家分月排行榜第二2013年10月 硬件/嵌入开发大版内专家分月排行榜第二2013年8月 硬件/嵌入开发大版内专家分月排行榜第二2013年3月 硬件/嵌入开发大版内专家分月排行榜第二2012年12月 硬件/嵌入开发大版内专家分月排行榜第二2012年11月 硬件/嵌入开发大版内专家分月排行榜第二2011年12月 硬件/嵌入开发大版内专家分月排行榜第二
2014年4月 硬件/嵌入开发大版内专家分月排行榜第三2014年1月 硬件/嵌入开发大版内专家分月排行榜第三2013年12月 硬件/嵌入开发大版内专家分月排行榜第三2013年11月 硬件/嵌入开发大版内专家分月排行榜第三2013年4月 硬件/嵌入开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。45959人阅读
今天写了一个更新UI的小例子,没想到出了log打印了这样一个错误:Only the original thread that created a view hierarchy can touch its views。goolgle了一下找到了原因。
原来android中相关的view和控件不是线程安全的,我们必须单独做处理。这里借此引出Handler的使用。
&&Handler的官方描述:
A Handler allows you to send and process&&and Runnable objects associated with a thread's&. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue
.Handler的使用场合:
1、&to schedule messages and runnables to be executed as some
&&&&& 安排messages和runnables在将来的某个时间点执行。
2、 to enqueue an action to be performed on a different thread than your own.
&&&&& 将action入队以备在一个不同的线程中执行。即可以实现线程间通信。比如当你创建子线程时,你可以再你的子线程中拿到父线程中创建的Handler对象,就可以通过该对象向父线程的消息队列发送消息了。由于Android要求在UI线程中更新界面,因此,可以通过该方法在其它线程中更新界面。
通过Handler更新UI实例:
1、创建Handler对象(此处创建于主线程中便于更新UI)。
2、构建Runnable对象,在Runnable中更新界面。
3、在子线程的run方法中向UI线程post,runnable对象来更新UI。
详细代码如下:
package djx.
import djx.downLoad.DownF
import android.app.A
import android.os.B
import android.os.H
import android.view.V
import android.view.View.OnClickL
import android.widget.B
import android.widget.TextV
public class downLoadPractice extends Activity {
private Button button_submit=
private TextView textView=
private String content=
private Handler handler=
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//创建属于主线程的handler
handler=new Handler();
button_submit=(Button)findViewById(R.id.button_submit);
textView=(TextView)findViewById(R.id.textView);
button_submit.setOnClickListener(new submitOnClieckListener());
//为按钮添加监听器
class submitOnClieckListener implements OnClickListener{
public void onClick(View v) {
//本地机器部署为服务器,从本地下载a.txt文件内容在textView上显示
final DownFiles df=new DownFiles("http://192.168.75.1:8080/downLoadServer/a.txt");
textView.setText("正在加载......");
new Thread(){
public void run(){
content=df.downLoadFiles();
handler.post(runnableUi);
}.start();
// 构建Runnable对象,在runnable中更新界面
runnableUi=new
Runnable(){
public void run() {
//更新界面
textView.setText("the Content is:"+content);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:140794次
积分:1759
积分:1759
排名:第9099名
原创:62篇
转载:41篇
评论:30条
(1)(2)(1)(2)(1)(1)(1)(1)(1)(2)(6)(7)(10)(3)(4)(1)(6)(4)(11)(16)(3)(7)(1)(5)(6)4558人阅读
UIWebView 的touch事件的捕捉:
- (void)viewDidLoad{
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
self.webView.delegate=
NSString *resourcePath = [ [NSBundle mainBundle] resourcePath];
& && NSString *filePath = [resourcePath stringByAppendingPathComponent:@"test.html"];
NSString *htmlstring=[[NSString alloc] initWithContentsOfFile:filePath& encoding:NSUTF8StringEncoding error:nil];
NSString *newHTMLString=[htmlstring stringByAppendingString:@"&script
language=/"javascript/"&document.ontouchstart=function(){& & & & &
document.location=/"myweb:touch:start/";& }; document.ontouchend=function(){& & & & &
document.location=/"myweb:touch:end/";& }; document.ontouchmove=function(){& & & & &
document.location=/"myweb:touch:move/";& }& &/script&"];
[self.webView loadHTMLString:newHTMLString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
bundlePath]]];
[htmlstring release];
webView.backgroundColor = [UIColor redColor];
webView.frame = CGRectMake(0, 0, 768, 1024);
[self.view addSubview:webView];
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
& & NSString *requestString = [[request URL] absoluteString];
& & NSArray *components = [requestString componentsSeparatedByString:@":"];
& & if ([components count] & 1 && [(NSString *)[components objectAtIndex:0] isEqualToString:@"myweb"]) {
& & & & if([(NSString *)[components objectAtIndex:1] isEqualToString:@"touch"])
& & & & & & NSLog(@"%@",[components objectAtIndex:2]);
& & & & return NO;
& & return YES;
UIScrollView上touch事件的捕捉:
创建一个继承于UIScrollView的类,
@interface MyScrollView : UIScrollView {
并改写其touch方法;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(!self.dragging)
[[self nextResponder] touchesBegan:touches withEvent:event];
[super touchesBegan:touches withEvent:event];
//NSLog(@"MyScrollView touch Began");
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if(!self.dragging)
[[self nextResponder] touchesEnded:touches withEvent:event];
[super touchesEnded:touches withEvent:event];
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:58613次
排名:第18947名
原创:34篇
转载:36篇
(2)(11)(1)(7)(1)(2)(6)(1)(1)(1)(2)(1)(3)(1)(2)(1)(3)(7)(2)(2)(2)(5)(1)(4)(1)MKMapView响应touch事件 - zani的博客 - ITeye技术网站
博客分类:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0 font: 14.0px 'Lucida Grande'; color: #929292}
TapDetectingWindow.h
NBFisheryiPad
Created by shiqyn on 11-6-16.
Copyright 2011 Stongsoft. All rights reserved.
#import &Foundation/Foundation.h&
@protocol TapDetectingWindowDelegate&NSObject&
- (void)userDidTapObserveView:(id)tapP
@interface TapDetectingWindow : UIWindow {
UIView *viewToO
id &TapDetectingWindowDelegate& controllerThatO
@property (nonatomic, retain) UIView* viewToO
@property (nonatomic, assign) id &TapDetectingWindowDelegate& controllerThatO
TapDetectingWindow.m
NBFisheryiPad
Created by shiqyn on 11-6-16.
Copyright 2011 Stongsoft. All rights reserved.
#import "TapDetectingWindow.h"
@implementation TapDetectingWindow
@synthesize viewToO
@synthesize controllerThatO
- (id)initWithViewToObserver:(UIView *)view andDelegate:(id)delegate {
if(self == [super init]) {
self.viewToObserve =
self.controllerThatObserves =
- (void)dealloc {
[viewToObserve release];
[super dealloc];
- (void)forwardTap:(id)touch
[controllerThatObserves userDidTapObserveView:touch];
- (void)sendEvent:(UIEvent *)event
[super sendEvent:event];
if (viewToObserve == nil || controllerThatObserves == nil)
NSSet *touches = [event allTouches];
if (touches.count != 1)
UITouch *touch = touches.anyO
if (touch.phase != UITouchPhaseEnded)
if ([touch.view isDescendantOfView:viewToObserve] == NO)
CGPoint tapPoint = [touch locationInView:viewToObserve];
NSArray *pointArray = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%f", tapPoint.x],
[NSString stringWithFormat:@"%f", tapPoint.y], nil];
if (touch.tapCount == 1)
[self performSelector:@selector(forwardTap:)
withObject:pointArray afterDelay:0];
else if (touch.tapCount & 1)
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(forwardTap:)
object:pointArray];
1.双击MainWindow.xib, 弹出的Window,按control+2,弹出的window attributes窗口中 将class identity设置成TapDetectingwindow.
2.在要使用TapDetectingwindow类中添加如下代码:
TapDetectingWindow* tapDetectWindow = ((TapDetectingWindow *)[[UIApplication sharedApplication].windows objectAtIndex:0]);
tapDetectWindow.viewToObserve = mapV
tapDetectWindow.controllerThatObserves =
并实现delegate:
#pragma mark TapDetectingWindowDelegate
- (void)userDidTapObserveView:(id)tapPoint
DLog(@"&&&userDidTapObserveView");
[self hideSearchRangeSlider];
浏览: 115916 次
来自: 福州
太 感谢 了!!!其他地方说的都只有一半!!
你这个效果有渐变吗?
不对啊。这是遍历 value啊
学习啦,加油
如果有xib文件需要增加一个language,这样调用选择图片 ...

我要回帖

更多关于 ipod touch好用吗 的文章

 

随机推荐