
1. 建立一个新的View Based项目。
你可以随意为其取名,我为其命名为TextFieldInAlert。
2. 代码
在viewcontroller.m或TextFieldInAlert.m(如果你命名为TextFieldInAlert的话),然后找到-(void)viewDidLoad方法。取消其注释加入代码。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
-
} |
我们做的是调用UIAlertView然后添加一个UITextField。你可能注意到了UIAlertView的message部分,我们为其赋值为“this getscovered!”,如果我们不为其加上这个语句,那么alert的按钮会更靠上而弄乱UITextField。你可以试一下拿掉这一行看看会发生什么。现在UITextField出现在UIAlertView中间了。试一下在UITextField输入点什么。噢,为什么键盘盖住了UIAlertView?有一个简单的修正方法。只需加入两行代码就可修正这个问题。加入代码:
|
1 2 3 |
|
完整代码如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
CGAffineTransformMake
Returns an affine transformation matrix constructed from values youprovide.
CGAffineTransform CGAffineTransformMake (
);
Parameters
a
The value at position [1,1] in the matrix.
b
The value at position [1,2] in the matrix.
c
The value at position [2,1] in the matrix.
d
The value at position [2,2] in the matrix.
tx
The value at position [3,1] in the matrix.
ty
The value at position [3,2] in the matrix.
Return Value
A new affine transform matrix constructed from the values youspecify.
Discussion
This function creates a CGAffineTransform structure that representsa new affine transformation matrix, which you can use (and reuse,if you want) to transform a coordinate system. The matrix takes thefollowing form:
|a
|c
|tx ty 1|
本文介绍如何在iOS应用中创建弹出式输入框,并通过使用CGAffineTransform来调整键盘遮挡问题,确保输入框在键盘下仍然可见。
3599

被折叠的 条评论
为什么被折叠?



