为iphone数字键盘添加完成按钮0+

56,201 views / 2011.06.25 / 9:09 下午

If you have ever written an iPhone app that requires numeric input, then you surely know about the UIKeyboardTypeNumberPad. And if you have ever used that flavor of the iPhone’s keyboard, then you surely know that it lacks one very important feature: The UIKeyboardTypeNumberPad does not have a “return” key.

In fact every other keyboard type (except for the pretty similar UIKeyboardTypePhonePad) does offer the possibility to be dismissed by setting the returnKeyType property of the corresponding UITextInputTraits implementor. So how does one achieve the same effect with the number pad? We have found a workround!

When looking at the number pad, you’ll notice that there is an unused space on its bottom left. That’s where we are going to plug in our custom “return” key.

To make it short: take a screenshot, cut out the whole backspace key, flip it horizotally, clear its backspace symbol in Photoshop and overlay it with the text that we want on our “return” key. We’ve chosen to label it “DONE”. Now we have the image for our custom button’s UIControlStateNormal. Repeat the whole procedure (with a touched backspace key when taking the screenshot) to get a second image for our button’s UIControlStateHighlighted. Here’s the result:

Now back to coding. First we need to know when the number pad is going to be slided up on the screen so we can plug in our custom button before that happens. Luckily there’s a notification for exactly that purpose, and registering for it is as easy as:

 
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(keyboardWillShow:) 
                                             name:UIKeyboardWillShowNotification 
                                           object:nil];

Don’t forget to remove the observer from the notification center in the appropriate place once you’re done with the whole thing:

 
[[NSNotificationCenter defaultCenter] removeObserver:self];

Now we’re getting to the heart of it. All we have to do in the keyboardWillShow method is to locate the keyboard view and add our button to it. The keyboard view is part of a second UIWindow of our application as others have already figured out (see this thread). So we take a reference to that window (it will be the second window in most cases, so objectAtIndex:1 in the code below is fine), traverse its view hierarchy until we find the keyboard and add the button to its lower left:

 
- (void)keyboardWillShow:(NSNotification *)note {  
    // create custom button
    UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
    doneButton.frame = CGRectMake(0, 163, 106, 53);
    doneButton.adjustsImageWhenHighlighted = NO;
    [doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
    [doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard view found; add the custom button to it
        if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
            [keyboard addSubview:doneButton];
    }
}

Voilà, that’s it! The empty space for our button starts at coordinate (0, 163) and has the dimensions (106, 53). The doneButton method has to be written now of course, but that’s not hard any more. Just make sure that you call resignFirstResponder on the text field that is being edited to have the keyboard slide down.

We’re “DONE”.

 

本文例子 downloaded as Xcode project
更新: download 3.0 compatible Xcode project.
最新的: download the newest version (可运行 2.0 – 4.0所有版本)

 

来源:http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key

Categories: 分享 Tags:

问:ios开发下使用什么命令能退出iphone应用?0+

85,597 views / 2011.05.29 / 11:11 下午

There is no API provided for gracefully terminating an iPhone application. Under the iPhone OS, the user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take – turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.

WARNING: It is possible to quit the application by calling exit. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen. Such usage provides a negative experience and is strongly discouraged.

Categories: 分享 Tags:

Discuz7.2 IE9兼容性–杜工完全修补方案0+

76,042 views / 2011.04.22 / 6:06 下午
现象:
1. IE9快速发帖不跳转
2. IE9管理员处理帖子失败
3. IE9登录不跳转,需要手动刷新
原因:
1. AJAXPOST函数判断out了
2. 动态创建iframe时各浏览器处理方式不同
解决方法:
1. 修改templates/header.htm
<meta http-equiv=”x-ua-compatible” content=”ie=7″ />
替换为
<!–[if lte IE 8]>
 <meta http-equiv=”x-ua-compatible” content=”ie=7″ /> <![endif]–>
<!–[if IE 9]>
<meta http-equiv=”x-ua-compatible” content=”ie=9″ />
<![endif]–>
2.修改include/js/common.js
把ajaxpost函数替换为:
function ajaxpost(formid, showid, waitid, showidclass, submitbtn, recall) {
 var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
 var showidclass = !showidclass ? '' : showidclass;
 var ajaxframeid = 'ajaxframe';
 var ajaxframe = $(ajaxframeid);
 var formtarget = $(formid).target;
 
var handleResult = function() {
 var s = '';
 var evaled = false;
 
showloading('none');
 try {
 s = $(ajaxframeid).contentWindow.document.XMLDocument.text;
 } catch(e) {
 try {
 s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.wholeText;
 } catch(e) {
 try {
 s = $(ajaxframeid).contentWindow.document.documentElement.firstChild.nodeValue;
 } catch(e) {
 s = '内部错误,无法显示此内容';
 }
 }
 }
 
if(s != '' && s.indexOf('ajaxerror') != -1) {
 evalscript(s);
 evaled = true;
 }
 if(showidclass) {
 $(showid).className = showidclass;
 if(submitbtn) {
 submitbtn.disabled = false;
 }
 }
 if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror)) {
 ajaxinnerhtml($(showid), s);
 }
 ajaxerror = null;
 if($(formid)) $(formid).target = formtarget;
 if(typeof recall == 'function') {
 recall();
 } else {
 eval(recall);
 }
 if(!evaled) evalscript(s);
 ajaxframe.loading = 0;
 $('append_parent').removeChild(ajaxframe);
 };
 if(!ajaxframe) {
 try{
 ajaxframe = document.createElement('<iframe name="' + ajaxframeid + '" id="' + ajaxframeid + '"></iframe>');
 }catch(e){
 ajaxframe = document.createElement('iframe');
 ajaxframe.name = ajaxframeid;
 ajaxframe.id = ajaxframeid;
 }
 ajaxframe.style.display = 'none';
 ajaxframe.loading = 1;
 $('append_parent').appendChild(ajaxframe);
 } else if(ajaxframe.loading) {
 return false;
 }
 
_attachEvent(ajaxframe, 'load', handleResult);
 
showloading();
 $(formid).target = ajaxframeid;
 $(formid).action += '&inajax=1';
 $(formid).submit();
 return false;
}
后台刷新缓存,搞定。
Categories: 感悟 Tags: ,

CentOS或者redhad下用yum或者rpm安装了 mysql 及 mysql-server , 在编译安装php时用 –with-mysql 选项出现错误

Note that the MySQL client library is not bundled anymore.

首先使用命令find / -name ‘mysql.h’ 查找路径,如果找到就给with-mysql=赋上路径,如果找不到,那就是缺少了 mysql-devel 安装包,用yum或者rpm安装上,即可解决问题

Categories: 感悟 Tags: ,

推荐本站使用的免备案高性价比美国VPS0+

55,997 views / 2011.03.30 / 5:05 下午

近来总是有朋友询问购买服务器是事情,又担心备案周期长,很是恼火。杜工正好推荐本站长期使用的VPS–DiaHosting。
DiaHosting旨在为广大中国站长提供自主管理的美国优质VPS,所有VPS均采用Xen虚拟技术,保证了VPS的质量,同时也是国内首家提供Xen-Shell管理平台的VPS供应商,加上二次开发的重装系统功能,Xen-Shell完全可以满足用户需求,本站使用的VPS就是一款拥有最高管理权限完全自主的产品。
大家可以看下DiaHosting的数据中心,顺便选个适合自己的线路:

洛杉矶数据中心

100MB 下载速度测试
测试IP: 67.215.238.117

拉斯维加斯数据中心

50MB 下载速度测试
测试IP: 208.64.24.6

西雅图SoftLayer数据中心

100MB 下载速度测试
测试IP: 67.228.118.21

达拉斯SoftLayer数据中心

100MB 下载速度测试
测试IP: 66.228.118.51

温馨提示,这家支持优惠码的哦。

最新优惠码 (二选一):

优惠码: 10%OFF 终身10%优惠

优惠码: FREEDA 适用于X360或X360以上型号, 免费DirectAdmin控制面板

预付优惠:

季付即可获得额外 5% 的折扣
半年付即可获得额外 10% 的折扣
年付即可获得额外 15% 的折扣

推荐理由:中文客服/支持中文支付/中国访问速度很好/口碑不错/性价比高

购买地址:链接>>

Categories: 感悟 Tags: