一点一滴,编程人生

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  69 随笔 :: 0 文章 :: 25 评论 :: 0 Trackbacks

#

文章出处:http://blog.csdn.net/iukey

UIKit提供了一组控件:UISwitch开关、UIButton按钮、UISegmentedControl分段控件、UISlider滑块、UITextField文本字段控件、UIPageControl分页控件。

控件是对UIView派生类的实用增强及补充,并可以直接附着于导航栏、表格单元,甚至更大的对象。

这些控件的基类均是UIControl,而UIControl派生自UIView类,所以每个控件都有很多视图的特性,包括附着于其他视图的能力。所有控件都拥有一套共同的属性和方法。

所以学习控件,我们先学习UIControl。

属性

enabled

控件默认是启用的。要禁用控件,可以将enabled属性设置为NO,这将导致控件忽略任何触摸事件。被禁用后,控件还可以用不同的方式显示自己,比如变成灰色不可用。虽然是由控件的子类完成的,这个属性却存在于UIControl中。

selected

当用户选中控件时,UIControl类会将其selected属性设置为YES。子类有时使用这个属性来让控件选择自身,或者来表现不同的行为方式。

contentVerticalAlignment

控件如何在垂直方向上布置自身的内容。默认是将内容顶端对其,对于文本字段,可能会改成UIControlContentVerticalAlignmentCenter。对于这个字段,可以使用下列诸值:

  1. UIControlContentVerticalAlignmentCenter  
  2. UIControlContentVerticalAlignmentTop  
  3. UIControlContentVerticalAlignmentBottom  
  4. UIControlContentVerticalAlignmentFill  
contentHorizontalAlignment

水平对齐方式,可以只用下列值:

  1. UIControlContentHorizontalAlignmentCenter  
  2. UIControlContentHorizontalAlignmentTop  
  3. UIControlContentHorizontalAlignmentBottom  
  4. UIControlContentHorizontalAlignmentFill  

事件通知

UIControl类提供了一个标准机制,来进行事件登记和接收。这令你可以指定你的控件在发生特定事件时,通知代理类的一个方法。如果要注册一个事件,可以使用addTarget方法:

  1. [ myControl addTarget: myDelegate   
  2.             action:@selector(myActionmethod:)  
  3.             forControlEvents:UIControlEventValueChanged ];  
事件可以用逻辑OR合并在一起,因此可以再一次单独的addTarget调用中指定多个事件。下列事件为基类UIControl所支持,除非另有说明,也适用于所有控件。

UIControlEventTouchDown

单点触摸按下事件:用户点触屏幕,或者又有新手指落下的时候。

UIControlEventTouchDownRepeat

多点触摸按下事件,点触计数大于1:用户按下第二、三、或第四根手指的时候。

UIControlEventTouchDragInside

当一次触摸在控件窗口内拖动时。

UIControlEventTouchDragOutside

当一次触摸在控件窗口之外拖动时。

UIControlEventTouchDragEnter

当一次触摸从控件窗口之外拖动到内部时。

UIControlEventTouchDragExit

当一次触摸从控件窗口内部拖动到外部时。

UIControlEventTouchUpInside

所有在控件之内触摸抬起事件。

UIControlEventTouchUpOutside

所有在控件之外触摸抬起事件(点触必须开始与控件内部才会发送通知)。

UIControlEventTouchCancel

所有触摸取消事件,即一次触摸因为放上了太多手指而被取消,或者被上锁或者电话呼叫打断。

UIControlEventTouchChanged

当控件的值发生改变时,发送通知。用于滑块、分段控件、以及其他取值的控件。你可以配置滑块控件何时发送通知,在滑块被放下时发送,或者在被拖动时发送。

UIControlEventEditingDidBegin

当文本控件中开始编辑时发送通知。

UIControlEventEditingChanged

当文本控件中的文本被改变时发送通知。

UIControlEventEditingDidEnd

当文本控件中编辑结束时发送通知。

UIControlEventEditingDidOnExit

当文本控件内通过按下回车键(或等价行为)结束编辑时,发送通知。

UIControlEventAlltouchEvents

通知所有触摸事件。

UIControlEventAllEditingEvents

通知所有关于文本编辑的事件。

UIControlEventAllEvents

通知所有事件。

除了默认事件以外,自定义控件类还可以用0x0F000000到0x0FFFFFFF之间的值,来定义他们自己的时间。

要删除一个或多个事件的相应动作,可以使用UIControl类的removeTarget方法。使用nil值就可以将给定事件目标的所有动作删除:

  1. [ myControl removeTarget:myDelegate   
  2.                   action:nil  
  3.                   forControlEvents:UIControlEventAllEvents];  
要取得关于一个控件所有指定动作的列表,可以使用allTargets方法。这个方法返回一个NSSet,其中包含事件的完整列表:

  1. NSSet* myActions = [myConreol allTargets ];  
另外,你还可以用actionsForTarget方法,来获取针对某一特定事件目标的全部动作列表:
  1. NSArray* myActions = [ myControl actionForTarget:UIControlEventValueChanged ];  

如果设计了一个自定义控件类,可以使用sendActionsForControlEvent方法,为基本的UIControl事件或自己的自定义事件发送通知。例如,如果你的控件值正在发生变化,就可以发送相应通知,通过控件的代码可以指定时间目标,这个通知将被传播到这些指定的目标。例:

  1. [ self sendActionsForControlEvents:UIControlEventValueChanged ];  
当委托类得到事件通知时,他将收到一个指向事件发送者的指针。下面的例子用于处理分段控件的事件,你的动作方法(action method)应遵循类似的处理方式:

  1. -(void) myAction:(id)sender{  
  2.        UISegmentedControl* control = (UISegmentedControl*)sender;  
  3.        if(control == myControl1){  
  4.         /*查询控件得值*/  
  5.       /*响应myControl1的动作*/  
  6.        }  
  7. }  

此文到此结束,如果你能耐心看看这篇文章,对你后面具体的控件会有事半功倍的效果。
posted @ 2012-04-28 17:21 writegull 阅读(2884) | 评论 (1)编辑 收藏

保存你的私钥,转移到其它系统

将你的私钥安全的保存,如果你需要在多台电脑上开发或者重装你的操作系统的。如果没有私钥,那么将无法再Xcode签名或者在apple设备上测试应用。当一个CSR被生成,Keychain Access应用在你的登录keychain里面生成一个私钥,这个私钥是和你的用户账户关联的,如果在系统重装的时候是无法重新生成的。如果你希望在多个系统上做开发或者测试,那么你需要在所有你工作的系统之上导入你的私钥。

1、 导出私钥和数字证书是为安全保存和能够在多台电脑上进行工作。打开Keychain Access应用选择’KEY’分类。

2、 右键点击和你iphone开发证书关联的私钥,并在弹出菜单中选择导出选项。

3、 使用(.p12)保存包含了你个人信息的钥匙。

4、 你将会被提示创建一个密码。

现在可以通过.p12文件在不同系统之间传输。双击.p12在其他系统上进行安装。输入你在step4输入的密码。

posted @ 2012-04-27 10:40 writegull 阅读(610) | 评论 (0)编辑 收藏

   在编译好的真机版目录下的.app文件,至于生成真机可以运行的app的方法,有两种方式,一种是交99美元获得一个证书,另外一种是破解的方式,在此不再详述,本文假设你已经生成了真机上可以运行的app包了(app包实际上是一个文件夹

   假设此安装包的名称是 hello.app,点击右键,选择 显示包内容,这样就可以打开这个hello.app文件夹了,在此文件夹中有一个info.plist文件,打开它,新增加一个名为SignerIdentity的key字段,内容为Apple iPhone OS Application Signing。

然后将.app拖到itunes就生成ipa了.默认名字应该是hello.ipa

如果要将此ipa分发出去,可以在itunes中的hello.ipa文件上点击鼠标右键,选择 在finder中显示,就可以得到生成后的ipa安装文件了

posted @ 2012-04-26 09:50 writegull 阅读(1167) | 评论 (0)编辑 收藏

1.在Windows下打开/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk/SDKSettings.plist ,找到CODE_SIGNING-REQUIRED 将它对应的值改为NO。

2.打开Xcode创建/打开一个项目,把Code signing identity和Any ios 对应的值改为Don’t Code Sign 

3.Build and Run!Enjoy!
posted @ 2012-04-26 09:42 writegull 阅读(219) | 评论 (0)编辑 收藏

1.程序图标app icon ------ 普屏 icon.png[57*57] 视网膜屏icon@2x.png[114*114]

iPhone开发中经常用到的控件尺寸大集合

Sizes of iPhone UI Elements


iPhone UI 设计的一些标准尺寸1 - 懒得喘气 - 懒得喘气的博客
ElementSize (in points)
Window (including status bar)320 x 480 pts
Status Bar
(How to hide the status bar)
20 pts
View inside window 
(visible status bar)
320 x 460
Navigation Bar44 pts
Nav Bar Image /
Toolbar Image
up to 20 x 20 pts (transparent PNG)
Tab Bar49 pts
Tab Bar Iconup to 30 x 30 pts (transparent PNGs)
Text Field31 pts
Height of a view inside 
a navigation bar
416 pts
Height of a view inside 
a tab bar
411 pts
Height of a view inside 
a navbar and a tab bar
367 pts
Portrait Keyboard height216 pts
Landscape Keyboard height140 pts
Points vs. Pixels
The iPhone 4 introduced a high resolution display with twice the pixels of previous iPhones. However you don't have to modify your code to support high-res displays; the coordinate system goes by points rather than pixels, and the dimensions in points of the screen and all UI elements remain the same.
iOS 4 supports high resolution displays (like the iPhone 4 display) via the scale property on UIScreen, UIView, UIImage, and CALayer classes. If the object is displaying high-res content, its scale property is set to 2.0. Otherwise it defaults to 1.0.
All you need to do to support high-res displays is to provide @2x versions of the images in your project. See the checklist for updating to iOS4 or Apple documentation for Supporting High Resolution Screens for more info.
Adjusting Sizes
Click here to see how to adjust View Frames and Bounds.
Additional References
Table 8-1  Custom icons and images

Description

Size for iPhone and iPod touch (in pixels)

Size for iPad (in pixels)

Guidelines

Application icon (required for all apps)

57 x 57

114 x 114 (high resolution)

72 x 72

“Application Icons”

App Store icon (required for all apps)

512 x 512

512 x 512

“Application Icons”

Launch image (required for all apps)

320 x 480

640 x 960 (high resolution)

For portrait:

  • 768 x 1004

For landscape:

  • 1024 x 748

“Launch Images”

Small icon for Spotlight search results and Settings (recommended)

29 x 29

58 x 58 (high resolution)

50 x 50 for Spotlight search results

29 x 29 for Settings

“Small Icons”

Document icon (recommended for custom document types)

22 x 29

44 x 58 (high resolution)

64 x 64

320 x 320

“Document Icons”

Web clip icon (recommended for web apps and websites)

57 x 57

114 x 114 (high resolution)

72 x 72

“Web Clip Icons”

Toolbar and navigation bar icon (optional)

Approximately 20 x 20

Approximately 40 x 40 (high resolution)

Approximately 20 x 20

“Icons for Navigation Bars, Toolbars, and Tab Bars”

Tab bar icon (optional)

Approximately 30 x 30

Approximately 60 x 60 (high resolution)

Approximately 30 x 30

“Icons for Navigation Bars, Toolbars, and Tab Bars”

Newsstand icon for the App Store (requiredfor Newsstand apps)

At least 512 pixels on the longest edge

At least 512 pixels on the longest edge

“Newsstand Icons”

posted @ 2012-04-26 09:31 writegull 阅读(8907) | 评论 (0)编辑 收藏

如果我们在Hibernate中需要查询多个表的不同字段,如何来获取结果呢?
有两种方式:
1、 对各个字段分别转化成对应类型,如下:

Java代码
  1. Query session.createQuery(select members, classInfo.className "    
  2.     from Members members, ClassInfo classInfo "    
  3.     where members.level classInfo.classCode ");    
  4.   
  5. List result q.list();    
  6. Iterator it result.iterator();    
  7. while (it.hasNext())    
  8.    Object[] tuple (Object[]) it.next();    
  9.    Members members (Members) tuple[ 0 ];    
  10.    String className (String) tuple[ 1 ];    
  11.  
 

2、构造自己的复合类型,如下:

Java代码
  1. Query session.createQuery(select new NewMembers(members, classInfo.className) "    
  2.     from Members members, ClassInfo classInfo "    
  3.     where members.level classInfo.classCode ");  

当然我们需要有一个NewMembers类和相应的构造方法。

posted @ 2012-04-24 09:34 writegull 阅读(535) | 评论 (0)编辑 收藏

有时我们写个代码开源出来给别人用时,会被其他开发者抱怨编译不了,很多情况是版本的问题,尤其现在ARC的出现后关于weak,strong的问题让人头疼。
有个开源代码这里做的很不错,就是MBProgressHUD
看下他是怎么做的:

  1. #ifndef MB_STRONG
  2. #if __has_feature(objc_arc)
  3.     #define MB_STRONG strong
  4. #else
  5.     #define MB_STRONG retain
  6. #endif
  7. #endif
  8.  
  9. #ifndef MB_WEAK
  10. #if __has_feature(objc_arc_weak)
  11.     #define MB_WEAK weak
  12. #elif __has_feature(objc_arc)
  13.     #define MB_WEAK unsafe_unretained
  14. #else
  15.     #define MB_WEAK assign
  16. #endif
  17. #endif

非ARC的retain,相当于ARC的strong
iOS5的ARC中weak能在销毁时自动赋值nil,这是iOS4.x上使用ARC不具备,所以用的unsafe,非ARC自然是assign

posted @ 2012-04-23 15:49 writegull 阅读(1408) | 评论 (0)编辑 收藏

release 是将内存引用计数-1  nil 直接赋值为0   除非这个指针指向的空间被释放  否则就是内存泄露

nil是表示0x0,可以理解为空指针。release是释放内存。
例如:你开辟了一块内存p=[[nsobject alloc] init]; 这个时候p是指向这块内存区域的,如果你直接p=nil,会造成这块内存没有被释放,内存泄露。 如果[p release]释放了内存,但是p还是指向这个内存地址,如果在操作p会出现EXC_BAD_ACCESS。正确的做法应该是释放后,把p指向nil
posted @ 2012-04-20 17:40 writegull 阅读(466) | 评论 (0)编辑 收藏

概述

UIView对象在屏幕中定义了一个复杂区域和界面来管理这个区域的内容

视图的职责:
画图和动画。
布局和子视图管理。

事件处理。

 

1、创建一个视图对象

CGRect viewRect = CGRectMake(10,10,100,100);
UIView* myView = [[UIView alloc] initWithFrame:viewRect];
[self.window addSubview :myView];//将视图作为子视图添加到window中

2、动画

改变一些视图属性将会使用到动画,改变属性时创建一个动画,用于给用户传递在较短时间内的变化。UIView类做了动画展现的大部分工作,但是你仍然需要声明哪种属性改变的时候,你需要动画效果。有两种不同的类型来初始化动画
下面的UIView属性支持动画:
frame,bounds,center,transform,alpha,backgroundColor,contentStretch
在iOS 4之后,使用block-based动画方法(推荐使用)
使用 开始/提交方式(begin/commit)

3、管理视图的层次结构

superview属性:
subviews属性:
window属性:
-addSubview方法
-bringSubviewToFront:(UIView *)veiw方法,将view视图移到层次结构的最顶端,使得其得以展示
-sendSubviewToBack:(UIView *)veiw方法,和上面方法正好相反
-removeFromSupview方法,
-insertSubview:(UIView *)view atIndex:(Interger)index方法
-insertSubview:(UIView *)view aboveSubview(UIView *)siblingView 方法
-insertSubview:(UIView *)view belowSubview(UIView *)siblingView 方法
-exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2方法
-isDescendantOfView:(UIView *)view方法,判断view是不是指定视图的子视图

4、子视图的布局(layout)

-layoutSubviews方法,这个方法,默认没有做任何事情,需要子类进行重写
-setNeedsLayout方法
-layoutIfNeeded方法,立即对子视图进行布局

5、画/更新视图

-drawRect:(CGRect)rect方法
-setNeedsDisplay
-setNeedsDisplayInRect:(CGRect)invalidRect方法

6、以块展现动画的方式(animating views with block)

+ animateWithDuration:delay:options:animations:completion:
+ animateWithDuration:animations:completion:
+ animateWithDuration:animations:
+ transitionWithView:duration:options:animations:completion:

+ transitionFromView:toView:duration:options:completion:

7、在视图和坐标系统之间转换

-convertPoint:toView
-convetPoint:fromView
-convertRect:toView
-convertRect:fromView

8、跟踪视图相关的改变

-didAddSubview:
-willRemoveSubview:
-willMoveToSuperview
-didMoveToSuperview
-willMoveToWindow:
-didMoveToWindow
posted @ 2012-04-20 10:37 writegull 阅读(9648) | 评论 (0)编辑 收藏

     摘要: 目前做的一个项目里用到了提示音,但是又不想添加提示音到库里,便开始研究调用系统自带的提示音,最后终于找到了。开始在CC上查发现好像很多人都在问,但没人回答,我就把自己查到的东西和写的一个demo给大家分享下吧首先要在工程里加入Audio Toolbox framework这个库,然后在需要调用的文件里#import <AudioToolbox/AudioToolbox.h>最后在需要播...  阅读全文
posted @ 2012-04-16 14:23 writegull 阅读(1940) | 评论 (0)编辑 收藏

仅列出标题
共7页: 上一页 1 2 3 4 5 6 7 下一页