当前位置:  编程技术>移动开发
本页文章导读:
    ▪对 键盘 事件 监听NSNotification 处置相应页面 变化UIKeyboardAnimation        对 键盘 事件 监听NSNotification 处理相应页面 变化UIKeyboardAnimation // //  ViewController.h //  UIKeyboardTextNotification // //  Created by tuxiangqi on 12-8-10. //  Copyright (c) 2012年 __MyCompanyName__. All rights reserved. //.........
    ▪ SYSZUXpinyin 只能用到arm下, x86上用不了        SYSZUXpinyin 只能用到arm上, x86下用不了     SYSZUXpinyin 只能用到arm上, x86下用不了。原因是SYSZUXpinyin的实现,用到了一个QWSinputMethod 的类,这个类是arm平台的qt库所特有的。还记得我们在终端.........
    ▪ 地图abc 定位       mapabc 定位先说说我的测试机器:nexus s,操作系统:android 4.1。以下的结果都是通过nexus s上测试通过。 还是直接上代码 package com.myMap; import java.util.ArrayList; import java.util.List; import android.R.drawa.........

[1]对 键盘 事件 监听NSNotification 处置相应页面 变化UIKeyboardAnimation
    来源: 互联网  发布时间: 2014-02-18
对 键盘 事件 监听NSNotification 处理相应页面 变化UIKeyboardAnimation

//

//  ViewController.h

//  UIKeyboardTextNotification

//

//  Created by tuxiangqi on 12-8-10.

//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.

//


#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate> {

    

}


@property (nonatomic, strong) UITableView *myTableView;


@end


//

//  ViewController.m

//  UIKeyboardTextNotification

//

//  Created by tuxiangqi on 12-8-10.

//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.

//


#import "ViewController.h"


@implementation ViewController



@synthesize myTableView;


-(void)viewDidLoad{

    [super viewDidLoad];

    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; 

    self.myTableView.delegate = self;

    self.myTableView.dataSource = self;

    

    self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    [self.view addSubview:self.myTableView];

}


-(void)viewDidUnload{

    [self setMyTableView:nil]; 

    [super viewDidUnload];

}



//页面出现前,添加监听 键盘事件

- (void) viewDidAppear:(BOOL)paramAnimated{ 

    [super viewDidAppear:paramAnimated];

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; 

    [center addObserver:self selector:@selector(handleKeyboardWillShow:)

                   name:UIKeyboardWillShowNotification  //键盘将出现 事件监听

                 object:nil];

    

    [center addObserver:self selector:@selector(handleKeyboardWillHide:)

                   name:UIKeyboardWillHideNotification  //键盘将隐藏 事件监听

                 object:nil];

}

- (void) viewDidDisappear:(BOOL)paramAnimated {

    [super viewDidDisappear:paramAnimated]; 

    [[NSNotificationCenter defaultCenter] removeObserver:self];

}



- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    /* Make sure the Done button on the keyboard for each text field (accessory views of each cell) dismisses the keyboard */ [textField resignFirstResponder];

    return YES;

}



- (void) handleKeyboardWillShow:(NSNotification *)paramNotification{

    NSDictionary *userInfo = [paramNotification userInfo];

    NSValue *animationCurveObject =[userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey];

    

    NSValue *animationDurationObject =[userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey]; 

    

    NSValue *keyboardEndRectObject =[userInfo valueForKey:UIKeyboardFrameEndUserInfoKey];

    

    NSUInteger animationCurve = 0;

    double animationDuration = 0.0f;

    CGRect keyboardEndRect = CGRectMake(0, 0, 0, 0);

    [animationCurveObject getValue:&animationCurve];

    [animationDurationObject getValue:&animationDuration]; 

    [keyboardEndRectObject getValue:&keyboardEndRect];

    

    [UIView beginAnimations:@"changeTableViewContentInset"

                    context:NULL];

    [UIView setAnimationDuration:animationDuration];

    [UIView setAnimationCurve:(UIViewAnimationCurve)animationCurve]; 

    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];

    CGRect intersectionOfKeyboardRectAndWindowRect = CGRectIntersection(window.frame, keyboardEndRect);

    CGFloat bottomInset = intersectionOfKeyboardRectAndWindowRect.size.height; 

    self.myTableView.contentInset = UIEdgeInsetsMake(0.0f,0.0f,bottomInset,0.0f);

    

    NSIndexPath *indexPathOfOwnerCell = nil;

    /* Also, make sure the selected text field is visible on the screen */

    NSInteger numberOfCells = [self.myTableView.dataSource tableView:self.myTableView

                                               numberOfRowsInSection:0];

    /* So let's go through all the cells and find their accessory text fields.

     Once we have the refernece to those text fields, we can see which one of

     them is the first responder (has the keyboard) and we will make a call

     to the table view to make sure after the keyboard is displayed,

     that specific cell is NOT obstructed by the keyboard */

    for (NSInteger counter = 0;counter < numberOfCells;counter++){

        

        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:counter inSection:0];

        

        UITableViewCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath];

        UITextField *textField = (UITextField *)cell.accessoryView;

        if ([textField isKindOfClass:[UITextField class]] == NO)

        {

            continue;

        }

        if ([textField isFirstResponder])

        {

            indexPathOfOwnerCell = indexPath;

            break;

        }

    }

    [UIView commitAnimations];

    if (indexPathOfOwnerCell != nil){

        [self.myTableView scrollToRowAtIndexPath:indexPathOfOwnerCell 

                                atScrollPosition:UITableViewScrollPositionMiddle

                                        animated:YES];

    }

}


- (void) handleKeyboardWillHide:(NSNotification *)paramNotification{ 

    if (UIEdgeInsetsEqualToEdgeInsets(self.myTableView.contentInset, UIEdgeInsetsZero))

    {

    /* Our table view's content inset is intact so no need to reset it */

    return;

}

    NSDictionary *userInfo = [paramNotification userInfo];

    NSValue *animationCurveObject =[userInfo valueForKey:UIKeyboardAnimationCurveUserInfoKey];

    NSValue *animationDurationObject = [userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey];

    NSValue *keyboardEndRectObject =[userInfo valueForKey:UIKeyboardFrameEndUserInfoKey];

    NSUInteger animationCurve = 0;double animationDuration = 0.0f;

    CGRect keyboardEndRect = CGRectMake(0, 0, 0, 0);

    [animationCurveObject getValue:&animationCurve]; 

    [animationDurationObject getValue:&animationDuration];

    [keyboardEndRectObject getValue:&keyboardEndRect];

    [UIView beginAnimations:@"changeTableViewContentInset" context:NULL];

    [UIView setAnimationDuration:animationDuration];

    [UIView setAnimationCurve:(UIViewAnimationCurve)animationCurve]; self.myTableView.contentInset = UIEdgeInsetsZero;[UIView commitAnimations];

}


- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

{

    return 1;

}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 100; 

}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    UITableViewCell *result = nil;

    static NSString *CellIdentifier = @"CellIdentifier";

    result = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (result == nil){

        result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault

                                        reuseIdentifier:CellIdentifier];

        

        result.selectionStyle = UITableViewCellSelectionStyleNone;

    }

    

    result.textLabel.text = [NSString stringWithFormat:@"Cell %ld", (long)indexPath.row];

    

    CGRect accessoryRect = CGRectMake(0.0f,

                                      0.0f,

                                      150.0f,

                                      31.0f);

    

    UITextField *accesssory = [[UITextField alloc] initWithFrame:accessoryRect]; 

    accesssory.borderStyle = UITextBorderStyleRoundedRect; 

    accesssory.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 

    accesssory.placeholder = @"Enter Text";

    accesssory.delegate = self;

    result.accessoryView = accesssory;

    

    return result;

}

@end




1楼lixing333前天 14:52系统自带的Notification Name,除了关于键盘的,还有没有其他的Notification?我没有找到相关资料Re: a21064346昨天 10:02回复lixing333nn官方的Documentation 里面涉及到的控件Notification 很少。除了键盘,还有一个是UIWindows.当然,还有一些其他的系统里又的notification,这个需要进行相关Document搜索。不过常用的就前面说的两个。一般 Notification 都是自己去自定义和管理收与发以及撤销。

    
[2] SYSZUXpinyin 只能用到arm下, x86上用不了
    来源: 互联网  发布时间: 2014-02-18
SYSZUXpinyin 只能用到arm上, x86下用不了

     SYSZUXpinyin 只能用到arm上, x86下用不了。原因是SYSZUXpinyin的实现,用到了一个QWSinputMethod

的类,这个类是arm平台的qt库所特有的。还记得我们在终端里启用qt程序后面要加个-qws参数,原因就在这。

       所以,用SYSZUXpinyin在arm平台尽管移植成功,但pc机上跑不了,增加了调试的复杂性。希望以后SYSZUXpinyin能考虑下这个问题!

     就为了在pc上跑通SYSZUXpinyin,浪费了我一个上午时间查资料


    
[3] 地图abc 定位
    来源: 互联网  发布时间: 2014-02-18
mapabc 定位

先说说我的测试机器:nexus s,操作系统:android 4.1。以下的结果都是通过nexus s上测试通过。

还是直接上代码

package com.myMap;

import java.util.ArrayList;
import java.util.List;

import android.R.drawable;
import android.R.integer;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationManager;
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.Toast;


import com.location.IONSetLocation;
import com.location.MyMapABCLocationListener;
import com.location.MyMapABCLocationManager;
import com.mapabc.mapapi.core.GeoPoint;
import com.mapabc.mapapi.core.OverlayItem;
import com.mapabc.mapapi.map.ItemizedOverlay;
import com.mapabc.mapapi.map.MapActivity;
import com.mapabc.mapapi.map.MapController;
import com.mapabc.mapapi.map.MapView;
import com.mapabc.mapapi.map.Overlay;
import com.mapabc.mapapi.map.Projection;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class MyMapActivity extends MapActivity implements OnClickListener{
    /** Called when the activity is first created. */
	private MapView mMapView;//地图VIEW
	private MapController mMapController;//控制器
	private List<Overlay> mOverlayList;	//地图图层容器
	private boolean mRegisteredSensor;
	private MyMapABCLocationListener mlLocationListener;
	private MyMapABCLocationManager mLocationManager;
	private MyOverlay mOverlay;   //我的位置图层
	private Handler mHandler;

	private boolean isFirstCenter=true;
	private GeoPoint geoPoint;
	private boolean isLocated=false;
	private Button btn;
	private Sensor orientSensor;
	private SensorManager mSensorManager;
	private SensorEventListener OrientSensorListener=new SensorEventListener(){		
		public void onAccuracyChanged(Sensor sensor,int accuracy){
			
		}
		public void onSensorChanged(SensorEvent event) {//从方向传感器获取手机所对的方向
			// TODO Auto-generated method stub
			if(event.sensor.getType()==Sensor.TYPE_ORIENTATION){
				float x=event.values[SensorManager.DATA_X];
				mOverlay.setDegree((int)x);
				mMapView.postInvalidate();//刷新mapview
			}
		}
 };
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mRegisteredSensor=false;
        mMapView = (MapView) findViewById(R.id.main_mapView);
        mMapView.setBuiltInZoomControls(true);  			// 设置启用内置的缩放控件
		mMapController = mMapView.getController();  		// 得到mMapView的控制权,可以用它控制和驱动平移和缩放
		mOverlayList = mMapView.getOverlays();				// 得到图层容器
		mMapController.setZoom(mMapView.getMaxZoomLevel()-1);//获取地图放大级别		
		btn=(Button)findViewById(R.id.search);
		btn.setOnClickListener(this);
		mOverlay=new MyOverlay(getResources().getDrawable(R.drawable.marker3));
		/////////////////////////////
		 mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
		 orientSensor=mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);		 
		////////////////////////////
		mOverlayList.add(mOverlay);
		initLogic();
    }
    @Override
    public void onClick(View v){
    	switch(v.getId()) {
    	case R.id.search:
    			if(geoPoint!=null){
    				mMapController.animateTo(geoPoint);
    			}
    		}
    	
    	
    }
      
    private void initLogic(){   	
    	mHandler=new Handler(){
    		@Override
    		public void handleMessage(Message msg){
    			switch (msg.what) {
				case 3:
					Toast.makeText(MyMapActivity.this, "location is null", Toast.LENGTH_SHORT).show();
					break;
				default:
					break;
				}
    		}
    	};
    	
    	mLocationManager=new MyMapABCLocationManager(this);
    	mlLocationListener=new MyMapABCLocationListener(mHandler, new UpdateLocationRunnable());
    	Location location=mLocationManager.getLastKnowLocation();
    	if(location!=null){
    		mOverlay.setLocation(location);
    		GeoPoint focusGeoPoint = new GeoPoint((int) (location.getLatitude() * 1E6),
					(int) (location.getLongitude() * 1E6));
		mMapController.animateTo(focusGeoPoint);
    		mMapView.postInvalidate();
    	}//////获取上次所在位置,如果不为null显示出来
    }
    public void firsCenter(Location location)
    {
    	if (location != null)
    	{
			GeoPoint focusGeoPoint = new GeoPoint((int) (location.getLatitude() * 1E6),
					(int) (location.getLongitude() * 1E6));
		
			mMapController.animateTo(focusGeoPoint);
    	}
    }
    @Override
    protected void onDestroy(){
    	super.onDestroy();
    	if(mOverlay!=null){
    		mOverlayList.clear();
    	}
    	mLocationManager.clear();
    }
    @Override//////////对于网络断开后重连,重要
    protected void onPause(){
    	super.onPause();
    	mLocationManager.unRegisterListen();
    	if(mRegisteredSensor){
			mSensorManager.unregisterListener(OrientSensorListener);
			mRegisteredSensor=false;
		}
    }
    @Override
    protected void onResume(){//////////对于网络断开后重连,重要
    	mLocationManager.registerListener(mlLocationListener);
    	Toast.makeText(this, "resume", Toast.LENGTH_SHORT).show();
    	mRegisteredSensor=mSensorManager.registerListener(OrientSensorListener, orientSensor,SensorManager.SENSOR_DELAY_GAME);
    	if(!mRegisteredSensor){
    		Toast.makeText(getApplicationContext(), "not support orientSensor", Toast.LENGTH_LONG).show();
    	}
    	super.onResume();
    }
    
    class UpdateLocationRunnable implements IONSetLocation{
    	private Location location;
    	private String address;
    	private boolean mVlid;
    	public UpdateLocationRunnable(){
    		
    	}
		@Override
		public void setAdress(String adress) {
			// TODO Auto-generated method stub
		}

		@Override
		public void setLocation(Location location) {
			// TODO Auto-generated method stub
			this.location=location;
		}		   
  
		@Override
		public void run() {
			// TODO Auto-generated method stub
			
			if(location!=null){				
			}else{
				Toast.makeText(MyMapActivity.this, "Gaode -->no location...", Toast.LENGTH_SHORT).show();
			}
			mOverlay.setLocation(location);
			if(isFirstCenter){
				firsCenter(location);
			}
			geoPoint= new GeoPoint((int) (location.getLatitude() * 1E6),(int) (location.getLongitude() * 1E6));
			mMapView.postInvalidate();//刷新地图
			}		
		}


  }/* * 我的位置图层 */class MyOverlay extends Overlay{private Location mLastLocation;private GeoPoint mLastGeoPoint;private Drawable drawable;private float degree;//图片旋转角度public MyOverlay(Drawable drawable){this.drawable=drawable;}public void setLocation(Location location){if (location != null){mLastLocation = location;mLastGeoPoint = new GeoPoint((int) (mLastLocation.getLatitude() * 1E6),(int) (mLastLocation.getLongitude() * 1E6));}}public void setDegree(float degree){this.degree=degree;}@Overridepublic void draw(Canvas canvas, MapView mapView, boolean shadow) {super.draw(canvas, mapView, shadow);// TODO Auto-generated method stub if (mLastLocation != null){ Projection projection = mapView.getProjection(); Point screenPts = new Point(); screenPts=projection.toPixels(mLastGeoPoint, null); Paint mPaint=new Paint(); mPaint.setColor(Color.BLUE); mPaint.setAlpha(5); float radius = projection.metersToEquatorPixels(mLastLocation.getAccuracy());canvas.drawCircle(screenPts.x, screenPts.y , radius, mPaint);//以精准度为半径画圆Bitmap bitmap=((BitmapDrawable)drawable).getBitmap();//画出“我的位置”图标Matrix matrix=new Matrix();matrix.setRotate(degree,0,0);bitmap=Bitmap.createBitmap(bitmap, 0, 0,bitmap.getWidth(), bitmap.getHeight(),matrix,false); canvas.drawBitmap(bitmap, screenPts.x-bitmap.getWidth()/2-0.5f,screenPts.y-bitmap.getHeight()/2-0.5f, new Paint());} }}

.MyMapABCLocationListener和MyMapABCLocationManager是参考别人代码封转的,由于篇幅的关系不给出来了(类详见代码:TestMapABCDemo.zip 很不错的参考代码)

 

我想说是旋转图片的问题。经过实践,如果一个图片经过旋转后,它的中心位置会发生改变。之前我的做法是获取原图的的中心位置,但是发现后面画出来的图片会“漂”

还有的是onResume和onDestory。注销了listener之后一定要把它注册回去,不然就不会监听消息了。

 

附件:myMap.rar

 

警告:android camera系列的文章是由一个刚接触android不到一个月的菜鸟所写,所以必然存在很多错误,请大家多多指出


 


    
最新技术文章:
▪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