首页 文章 精选 留言 我的

精选列表

搜索[Swift开发],共10000篇文章
优秀的个人博客,低调大师

Android开发学习笔记:手机震动控制浅析

Android系统中Vibrator对象负责对手机震动的处理,具体的实现方法: 1.获取振动器Vibrator的实例: Vibratorvibrator=(Vibrator)getSystemService(VIBRATOR_SERVICE); getSystemService(VIBRATOR_SERVICE):获得一个震动的服务 2.调用vibrate方法来产生震动: 只向vibrate()传递一个参数,这个参数用来指定振动的毫秒数 //震动5秒 vibrator.vibrate(5000); 向vibrate()方法传递多个参数 //等待1秒,震动2秒,等待1秒,震动3秒 long[]pattern={1000,2000,1000,3000}; //-1表示不重复,如果不是-1,比如改成1,表示从前面这个long数组的下标为1的元素开始重复. vibrator.vibrate(pattern,-1); 3.取消震动 vibrator.cancel(); 4.在AndroidManifest.xml文件添加权限 <uses-permissionandroid:name="android.permission.VIBRATE"/> 下面的实例包含了产生震动的两个方法 VibratorDemoActivity.java packagecom.lingdududu.test; importandroid.app.Activity; importandroid.os.Bundle; importandroid.os.Vibrator; importandroid.view.MotionEvent; /* *@authorlingdududu *当程序开始运行结束时,手机等待1秒就开始震动2秒,再等待1秒,开始震动3秒 *当我们点击手机屏幕,触发onTouchEvent事件,手机就开始震动1秒 */ publicclassVibratorDemoActivityextendsActivity{ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); Vibratorvibrator=(Vibrator)getSystemService(VIBRATOR_SERVICE); long[]pattern={1000,2000,1000,3000};//OFF/ON/OFF/ON...... vibrator.vibrate(pattern,-1); } @Override publicbooleanonTouchEvent(MotionEventevent){ if(event.getAction()==MotionEvent.ACTION_MOVE){ Vibratorvibrator=(Vibrator)getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(1000); } returnsuper.onTouchEvent(event); } } 注:记得在AndroidManifest.xml文件添加权限,还有程序要在真机上运行才能有震动的效果,模拟器上不支持震动的。 PS:我正在参加IT博客大赛,欢迎大家来投我一票的 http://blog.51cto.com/contest2011/3061169 本文转自 lingdududu 51CTO博客,原文链接:http://blog.51cto.com/liangruijun/724042

优秀的个人博客,低调大师

Android开发学习笔记:Notification和NotificationManager浅析

NotificationManager 获取NotificationManager String service = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager =(NotificationManager)getSystemService(service); Notification //实例化Notification Notificationnotification=newNotification(); 3.设置Notification的属性 //设置显示图标,该图标会在状态栏显示 inticon=notification.icon=R.drawable.happy; //设置显示提示信息,该信息也在状态栏显示 StringtickerText="测试Notification"; //显示时间 longwhen=System.currentTimeMillis();notification.icon=icon; notification.tickerText=tickerText; notification.when=when; //也可以这样设置 Notificationnotification_2=newNotification(icon,tickerText,when) 调用setLatestEventInfo()方法在视图中设置图标和时间。 //实例化Intent Intentintent=newIntent(MainActivity.this,MainActivity.class); //获得PendingIntent PendingIntentpIntent=PendingIntent.getActivity(MainActivity.this,0,intent,0); //设置事件信息 notification.setLatestEventInfo(MainActivity.this,"Title","Content",pIntent); 4.发出通知 //Notification标示ID privatestaticfinalintID=1; //发出通知 mNotificationManager.notify(ID,n); 下面是具体的例子,在这个例子里定义了一个MainActivity发出广播通知,定义一个MyReceiver类继承Broadcasts接受通知,当接收完通知之后,启动一个SecondActivity,在SecondActivity类中通过Notification和NotificationManager来可视化显示广播通知。具体的步骤如下: MainActivity.java packagecom.android.notification; importandroid.app.Activity; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; publicclassMainActivityextendsActivity{ //声明Button privateButtonbtn; //定义BroadcastReceiveraction privatestaticfinalStringMY_ACTION="com.android.notification.MY_ACTION"; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); //设置当前布局视图 setContentView(R.layout.main); //实例化Button btn=(Button)findViewById(R.id.Button1); //添加事件监听器 btn.setOnClickListener(listener); } //创建事件监听器 privateOnClickListenerlistener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ //实例化Intent Intentintent=newIntent(); //设置Intentaction属性 intent.setAction(MY_ACTION); //发起广播 sendBroadcast(intent); } }; } MyReceiver.java packagecom.android.notification; importandroid.content.BroadcastReceiver; importandroid.content.Context; importandroid.content.Intent; publicclassMyReceiverextendsBroadcastReceiver{ @Override publicvoidonReceive(Contextcontext,Intentintent){ //实例化Intent Intenti=newIntent(); //在新的任务中启动Activity i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //设置Intent启动的组件名称 i.setClass(context,SecondActivity.class); //启动Activity显示通知 context.startActivity(i); } } SecondActivity.java packagecom.android.notification; importandroid.app.Activity; importandroid.app.Notification; importandroid.app.NotificationManager; importandroid.app.PendingIntent; importandroid.content.Intent; importandroid.os.Bundle; importandroid.view.View; importandroid.view.View.OnClickListener; importandroid.widget.Button; publicclassSecondActivityextendsActivity{ //声明按钮 privateButtoncancelBtn; //声明Notification privateNotificationnotification; //声明NotificationManager privateNotificationManagermNotification; //Notification标示ID privatestaticfinalintID=1; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.second); //实例化按钮 cancelBtn=(Button)findViewById(R.id.cancelButton2); //获得NotificationManager实例 Stringservice=NOTIFICATION_SERVICE; mNotification=(NotificationManager)getSystemService(service); //实例化Notification notification=newNotification(); //设置显示图标,该图标会在状态栏显示 inticon=notification.icon=android.R.drawable.stat_notify_chat; //设置显示提示信息,该信息也会在状态栏显示 StringtickerText="TestNotification"; //显示时间 longwhen=System.currentTimeMillis(); notification.icon=icon; notification.tickerText=tickerText; notification.when=when; //实例化Intent Intentintent=newIntent(this,MainActivity.class); //获得PendingIntent PendingIntentpi=PendingIntent.getActivity(this,0,intent,0); //设置事件信息 notification.setLatestEventInfo(this,"消息","HelloAndroid",pi); //发出通知 mNotification.notify(ID,notification); //为按钮添加监听器 cancelBtn.setOnClickListener(cancelListener); } //取消通知监听器 privateOnClickListenercancelListener=newOnClickListener(){ @Override publicvoidonClick(Viewv){ //取消通知 mNotification.cancel(ID); } }; } main.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:text="发出广播通知" android:id="@+id/Button1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> second.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="显示通知界面" android:id="@+id/TextView1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="取消通知" android:id="@+id/cancelButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> 在AndroidManifest.xml文件中16~21加入对receiver,SecondActivity的声明 <?xmlversion="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.android.notification" android:versionCode="1" android:versionName="1.0"> <uses-sdkandroid:minSdkVersion="10"/> <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <activityandroid:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <receiverandroid:name="MyReceiver"> <intent-filter> <actionandroid:name="com.android.notification.MY_ACTION"/> </intent-filter> </receiver> <activityandroid:name="SecondActivity"/> </application> </manifest> 效果图: Notification丰富的提示方式: 声音提醒 ·使用默认声音 notification.defaults |= Notification.DEFAULT_SOUND; ·使用自定义声音 notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3"); ·注:如果定义了默认声音,那么自定义声音将被覆盖 振动提醒 ·使用默认振动 notification.defaults |= Notification.DEFAULT_VIBRATE; ·使用自定义振动 long[] vibrate = {0,100,200,300};notification.vibrate = vibrate; ·注:如果定义了默认振动,那么自定义振动将被覆盖 灯光闪烁提醒 ·使用默认闪烁 notification.defaults |= Notification.DEFAULT_LIGHTS; ·使用自定义闪烁 notification.ledARGB = 0xff00ff00;// LED灯的颜色,绿灯notification.ledOnMS = 300;// LED灯显示的毫秒数,300毫秒notification.ledOffMS = 1000;// LED灯关闭的毫秒数,1000毫秒notification.flags |= Notification.FLAG_SHOW_LIGHTS; // 必须加上这个标志 更多特性 可以通过 Notification 的相关字段或标志(flags)为提醒设置更多的特性。 ·FLAG_AUTO_CANCEL标志:当提醒被用户点击之后会自动被取消(cancel); ·FLAG_INSISTENT标志:在用户响应之前会一直重复提醒音; ·FLAG_ONGOING_EVENT标志:Add this to theflagsfield to group the notification under the "Ongoing" title in the Notifications window. ·FLAG_NO_CLEAR标志:当在提醒栏中点击“清除提醒”按钮时,该提醒将不会被清除; ·number字段:This value indicates the current number of events represented by the notification. The appropriate number is overlaid on top of the status bar icon. If you intend to use this field, then you must start with "1" when the Notification is first created. (If you change the value from zero to anything greater during an update, the number is not shown.) ·iconLevel字段:This value indicates the current level of aLevelListDrawablethat isused for the notification icon. You can animate the icon in the status bar by changingthis value to correlate with the drawable's defined in a LevelListDrawable. ·contentView字段:To define your own layout for the expanded message, instantiate a RemoteViews object and pass it to thecontentViewfield of your Notification. Pass the PendingIntent to thecontentIntentfield. 本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/657502

优秀的个人博客,低调大师

开发者指南-Android如何绘制View

Android画的操作是由Framework层来进行处理的,整个 draw是从根View开始的,ViewGroup向子View发出 draw的请求,然后子View负责自己重画它们的invalid区域。Drawing一个Layout必须通过两个步骤: 1. 测量。measure() 从根节点到叶子节点依次测量,这样每个View都会存有各自的dimension.在我们的程序种我们可以重写onMeasure来设置更为精确的content大小,重写完后必须调用setMeasureDimension来存储View的宽和高 。 2.布局。layout也是从父节点到子节点,父节点根据刚才传递进来的measure信息来拜访它们的子节点。 当一个视图的measure()方法返回时,它的getMeasuredWidth()和getMeasuredHeight() 值必须被设置,以及所有 这个视图子节点的值。一个view的measure的宽度和高度值必须符合父视图的限制。这确保在度量过程之后,所有父节点接受所有它们的子节点的度量值。一个父视图可能会在其子视图上多次调用measure()方法。比如,父视图可能会通过未指定的尺寸调用measure来找到它们的大小,然后使用实际数值再次调用measure(),如果所有子视图未做限制的尺寸总合过大或过小(也即是,如果子视图之间不能对各自占据的空间达成共识的话,父视图将会干预并且使用第二个过程的规则)。 View.MeasureSpec 用于子View告诉父View它们想如何被测量和怎么放置。而 LayoutParams则是描述了View的宽和高是多少。对于每一个区域可以指定如下的值: 一个准确的数值。 ·FILL_PARENT,这意味着视图想和父视图一样大(减掉填充padding)。 WRAP_CONTENT,这意味着视图只想有刚好包装其内容那么大(加上padding)。 对于不同的ViewGroup子类,有相应的LayoutParams子类。比如,相对布局RelativeLayout有它自己的LayoutParams子类,这包含了能够让子视图横向和竖向居中显示的能力。 度量规格(MeasureSpecs)被用来沿着树从父到子的下传度量需求。一个MeasureSpecs可以是下面三种模式之一: UNSPECIFIED:父视图来决定其子视图的理想尺寸。比如,一个线性布局可能在它的子视图上调用measure() on its child,通过设置其高度为UNSPECIFIED 以及一个宽度为EXACTLY 240,来找出这个子视图在给定240像素宽度的情况下需要显示多高。 EXACTLY:父视图用来给子视图强加一个准确的尺寸。子视图必须使用这个大小,并确保其所有的后代将适合这个尺寸。 AT_MOST:这被父视图用来给子视图强加一个最大尺寸。子视图必须确保它自己以及所有的后代都适合这个尺寸。 本文转自 最牛傻蛋 51CTO博客,原文链接:http://blog.51cto.com/zuiniuwang/718274,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS开发-自定义UIAlterView(iOS 7)

App中不可能少了弹框,弹框是交互的必要形式,使用起来也非常简单,不过最近需要自定义一个弹框,虽然iOS本身的弹框已经能满足大部分的需求,但是不可避免还是需要做一些自定义的工作。iOS7之前是可以自定义AlterView的,就是继承一下UIAlterView,然后初始化的时候通过addSubview添加自定义的View,但是iOS7之后这样做就不行了,不过还好有开源项目可以解决这个问题。 iOS默认弹框 viewDidLoad中添加两个按钮,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 UIButton *orignalBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 40, 100, 50)]; [orignalBtn setBackgroundColor:[UIColor greenColor]]; [orignalBtn setTitle:@ "iOS弹框" forState:UIControlStateNormal]; [orignalBtn addTarget: self action: @selector (orignalShow) forControlEvents:UIControlEventTouchUpInside]; [ self .view addSubview:orignalBtn]; UIButton *customlBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 140, 100, 50)]; [customlBtn setBackgroundColor:[UIColor redColor]]; [customlBtn setTitle:@ "自定义弹框" forState:UIControlStateNormal]; [customlBtn addTarget: self action: @selector (customShow) forControlEvents:UIControlEventTouchUpInside]; [ self .view addSubview:customlBtn]; 响应默认弹框事件: 1 2 3 4 -( void )orignalShow{ UIAlertView *alterView=[[UIAlertView alloc]initWithTitle:@ "提示" message:@ "博客园-Fly_Elephant" delegate: self cancelButtonTitle:@ "取消" otherButtonTitles:@ "确定" , nil ]; [alterView show]; } 效果如下: 自定义弹框 主要解决iOS7之后的系统无法自定义弹框的问题,使用开源项目,项目地址:https://github.com/wimagguc/ios-custom-alertview,其实就是自定义了一个类: CustomIOSAlertView.h 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #import <UIKit/UIKit.h> @protocol CustomIOSAlertViewDelegate - ( void )customIOS7dialogButtonTouchUpInside:( id )alertView clickedButtonAtIndex:( NSInteger )buttonIndex; @end @interface CustomIOSAlertView : UIView<CustomIOSAlertViewDelegate> @property ( nonatomic , retain) UIView *parentView; // The parent view this 'dialog' is attached to @property ( nonatomic , retain) UIView *dialogView; // Dialog's container view @property ( nonatomic , retain) UIView *containerView; // Container within the dialog (place your ui elements here) @property ( nonatomic , assign) id <CustomIOSAlertViewDelegate> delegate; @property ( nonatomic , retain) NSArray *buttonTitles; @property ( nonatomic , assign) BOOL useMotionEffects; @property ( copy ) void (^onButtonTouchUpInside)(CustomIOSAlertView *alertView, int buttonIndex) ; - ( id )init; /*! DEPRECATED: Use the [CustomIOSAlertView init] method without passing a parent view. */ - ( id )initWithParentView: (UIView *)_parentView __attribute__ (( deprecated )); - ( void )show; - ( void )close; - ( IBAction )customIOS7dialogButtonTouchUpInside:( id )sender; - ( void )setOnButtonTouchUpInside:( void (^)(CustomIOSAlertView *alertView, int buttonIndex))onButtonTouchUpInside; - ( void )deviceOrientationDidChange: ( NSNotification *)notification; - ( void )dealloc; @end CustomIOSAlertView.m + View Code 调用代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 -( void )customShow{ CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init]; [alertView setContainerView:[ self customView]]; [alertView setButtonTitles:[ NSMutableArray arrayWithObjects:@ "取消" , @ "确定" , nil ]]; [alertView setDelegate: self ]; [alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) { NSString *result=alertView.buttonTitles[buttonIndex]; NSLog (@ "点击了%@按钮" ,result); [alertView close]; }]; [alertView setUseMotionEffects: true ]; [alertView show]; } - (UIView *)customView { UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 160)]; UILabel *tip=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 50, 30)]; [tip setText:@ "提示" ]; [customView addSubview:tip]; UILabel *content=[[UILabel alloc]initWithFrame:CGRectMake(10, 60, 210, 30)]; [content setText:@ "http://www.cnblogs.com/xiaofeixiang" ]; [content setFont:[UIFont systemFontOfSize:12]]; [customView addSubview:content]; return customView; } 效果如下: 本文转自Fly_Elephant博客园博客,原文链接:http://www.cnblogs.com/xiaofeixiang/p/4453819.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

Android开发之旅:组件生命周期(一)

引言 应用程序组件有一个生命周期——一开始Android实例化他们响应意图,直到结束实例被销毁。在这期间,他们有时候处于激活状态,有时候处于非激活状态;对于活动,对用户有时候可见,有时候不可见。组件生命周期将讨论活动、服务、广播接收者的生命周期——包括在生命周期中他们可能的状态、通知状态改变的方法、及这些状态的组件寄宿的进程被终结和实例被销毁的可能性。 本文主要讨论活动的生命周期及他们可能的状态、通知状态改变的方法。分为以下三部分: 1、活动生命周期 2、保存活动状态 3、协调活动 1、活动生命周期 一个活动有三个基本状态: 激活状态或运行状态,这时它运行在屏幕的前台(处于当前任务活动栈的最上面)。这个活动有用户的操作的焦点。 暂停状态,这时活动失去焦点但是它对用户仍可见。也就是说,另一个活动在它的上面且那个活动是透明的或者没有覆盖整个屏幕,因此通过它可以看见暂停状态的活动。一个暂停的活动完全是活着的(它维护着所有的状态和成员信息,且仍然依附在窗口管理器),但是当内存极小时可以被系统杀掉。 停止状态,这时活动完全被其他活动掩盖。它仍然保留所有状态和成员信息,但是对用户它不可见,因此它的窗口时隐藏的且当其他地方需要内存时它往往被系统杀掉。 如果一个活动被暂停或停止,系统可以将它从内存移除,通过要求它结束(通过调用它的finish()方法),或简单地杀掉它的进程。当它再次显示给用户时,必须要完全重新启动和恢复到之前的状态。随着活动从一个状态转为另一个状态,通过调用下面的受保护的方法通知该改变: void onCreate(BundlesaveInstanceState) void onStart() void onRestart() void onResume() void onPause() void onStop() void onDestroy() 所有这些方法都是钩子,你可以重写当状态改变时做适当的工作。所有的活动必须要实现onCreate()去做一些初始化的设置,当对象第一次实例化的时候。很多活动也会实现onPause()去提交数据修改或准备停止与用户交互。 将他们合并在一起,这七个方法定义了活动的整个生命周期。有三个嵌套的循环,你可以通过这七个方法监视: 活动的整个生命时间,从第一次调用onCreate()开始直到调用onDestroy()结束。一个活动在onCreate()中做所有的“全局”状态的初始设置,在onDestroy()中释放所有保留的资源。举例来说,有一个线程运行在后台从网络上下载数据,它可能会在onCreate()中创建线程,在onDestroy()中结束线程。 活动的可视生命时间,从调用onStart()到相应的调用onStop()。在这期间,用户可以在屏幕上看见活动,虽然它可能不是运行在前台且与用户交互。在这两个方法之间,你可以保持显示活动所需要的资源。举例来说,你可以在onStart()中注册一个广播接收者监视影响你的UI的改变,在onStop()中注销。因为活动在可视和隐藏之间来回切换,onStart()和onStop()可以调用多次。 活动的前台生命时间,从调用onResume()到相应的调用onPause()。在这期间,频繁地在重用和暂停状态转换——例如,当设备进入睡眠状态或一个新的活动启动时调用onPause(),当一个活动返回或一个新的意图被传输时调用onResume()。因此,这两个方法的代码应当是相当轻量级的。 下面这个图解释了这三个循环和状态之间状态的可能路径。着色的椭圆表示活动的主要状态,矩形表示当活动在状态之间转换时你可以执行的回调方法。 图1、活动生命周期(来源:Android SDK) 下面的表格对每个方法更详细的描述和在活动的整个生命周期中的定位。 注意上面表格的Killable列,它表示当方法返回时没有执行活动的其它代码,系统是否能杀死活动寄宿的进程。三个方法(onPause()、onStop()、onDestroy())标记为Yes。因为onPause()是唯一一个保证在进程被杀之前会调用的,因此你应该使用onPause()来写任何持久化存储数据。 被标记为No的方法保护活动寄宿的进程在他们调用的时候不会被杀掉。因此活动是可杀掉状态,例如onPause()返回到onResume()调用期间。直到onPause()再次返回,活动是不可杀掉的。其实,没有标记为Killable的活动也是可以系统被杀掉的,不过这仅仅发生在极端困难的情况下,没有有任何其他资源可用。 2、保存活动状态 当系统而不是用户关闭一个活动来节省内存时,用户可能希望返回到活动且是它之前的状态。为了获得活动被杀之前的状态,你可以执行活动的onSaveInstanceState()方法。Android在活动容易被销毁前调用这个方法,也就是调用onPause()之前。该方法的参数是一个Bundle对象,在这个对象你可以以名值对记录活动的动态状态。当活动再次启动时,Bundle同时被传递到onCreate()和调用onCreate()之后的方法,onRestoreInstanceState(),因此使用一个或两个可以重新创建捕获的状态。 因为onSaveInstanceState()方法不总是被调用,你应该仅使用onSaveInstanceState()它来记录活动的临时状态,而不是持久的数据。应该使用onPause()来存储持久数据。 3、协调活动 当一个活动启动另一个活动,他们都经历生命周期转换。一个暂停或许是停止,然而另一个启动。有时,你可能需要协调这些活动。生命周期的回调顺序是明确界定的,特别是当这两个活动在同一个进程中: 当前活动的onPause()方法被调用。 接下来,启动活动的onCreate()、onStart()、onResume()方法按序被调用。 然后,如果获得不再在屏幕上可见,它的onStop()方法被调用。 修正:第一节——活动生命周期中的表格第一、二行中的第二列(description)中的onRestart()应该为onStart()。 1000多的点击,居然没有人发现这个错误,看了大家根本就没认真看或者说根本没有静心看园子里的任何博文,心痛!还是水帖比较受欢迎。 本文转自Saylor87 51CTO博客,原文链接:http://blog.51cto.com/skynet/365375,如需转载请自行联系原作者

优秀的个人博客,低调大师

UIKeyboard键盘相关知识点-IOS开发

一、键盘风格 UIKit框架支持8种风格键盘。 [java] view plain copy print ? typedefenum{ UIKeyboardTypeDefault,//默认键盘:支持所有字符 UIKeyboardTypeASCIICapable,//支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation,//标准电话键盘,支持+*#等符号 UIKeyboardTypeURL,//URL键盘,有.com按钮;只支持URL字符 UIKeyboardTypeNumberPad,//数字键盘 UIKeyboardTypePhonePad,//电话键盘 UIKeyboardTypeNamePhonePad,//电话键盘,也支持输入人名字 UIKeyboardTypeEmailAddress,//用于输入电子邮件地址的键盘 }UIKeyboardType; 用法用例: textView.keyboardtype =UIKeyboardTypeNumberPad; 二、键盘外观 [java] view plain copy print ? typedefenum{ UIKeyboardAppearanceDefault,//默认外观:浅灰色 UIKeyboardAppearanceAlert,//深灰/石墨色 }UIKeyboardAppearance; 用法用例: textView.keyboardAppearance=UIKeyboardAppearanceDefault; 三、回车键 typedefenum{ UIReturnKeyDefault, //默认:灰色按钮,标有Return UIReturnKeyGo,//标有Go的蓝色按钮 UIReturnKeyGoogle, //标有Google的蓝色按钮,用于搜索 UIReturnKeyJoin, //标有Join的蓝色按钮 UIReturnKeyNext, //标有Next的蓝色按钮 UIReturnKeyRoute, //标有Route的蓝色按钮 UIReturnKeySearch, //标有Search的蓝色按钮 UIReturnKeySend, //标有Send的蓝色按钮 UIReturnKeyYahoo, //标有Yahoo!的蓝色按钮,用于搜索 UIReturnKeyDone, //标有Done的蓝色按钮 UIReturnKeyEmergencyCall, //紧急呼叫按钮 }UIReturnKeyType; 用法用例: textView.returnKeyType=UIReturnKeyGo; 四、自动大写 [java] view plain copy print ? typedefenum{ UITextAutocapitalizationTypeNone,//不自动大写 UITextAutocapitalizationTypeWords,//单词首字母大写 UITextAutocapitalizationTypeSentences,//句子首字母大写 UITextAutocapitalizationTypeAllCharacters,//所有字母大写 }UITextAutocapitalizationType; 用法用例: textField.autocapitalizationType=UITextAutocapitalizationTypeWords; 五、自动更正 [java] view plain copy print ? typedefenum{ UITextAutocorrectionTypeDefault,//默认 UITextAutocorrectionTypeNo,//不自动更正 UITextAutocorrectionTypeYes,//自动更正 }UITextAutocorrectionType; 用法用例: textField.autocorrectionType=UITextAutocorrectionTypeYes; 六、安全文本输入 textView.secureTextEntry=YES; 开启安全输入主要是用于密码或一些私人数据的输入,此时会禁用自动更正和自此缓存。 原文来自:http://blog.csdn.net/iukey/article/details/7301150 七、键盘遮住视图 默认情况下打开键盘会遮住下面的view,带来一点点困扰,不过这不是什么大问题,我们使用点小小的手段就可以解决。 首先我们要知道键盘的高度是固定不变的,不过在IOS 5.0 以后键盘的高度貌似不是216了,不过不要紧,我们调整调整就是了: iPhone ipad 竖屏(portrait) 216 264 横屏(landScape) 140 352 我们采取的方法就是在textField(有可能是其他控件)接收到弹出键盘事件时把self.view整体上移216px了(我们就以iPhone竖屏为例了)。 有关View的frame,origin,size之类的知识点不懂的请参看我的另一篇博文: <<有关View的几个基础知识点>> 首先我们要设置textField的代理,我们就设为当前控制器了。 textField,delegate=self; 然后我们在当前控制器实现下面三个委托方法: [java] view plain copy print ? -(void)textFieldDidBeginEditing:(UITextField*)textField {//当点触textField内部,开始编辑都会调用这个方法。textField将成为firstresponder NSTimeIntervalanimationDuration=0.30f; CGRectframe=self.view.frame; frame.origin.y-=216; frame.size.height+=216; self.view.frame=frame; [UIViewbeginAnimations:@"ResizeView"context:nil]; [UIViewsetAnimationDuration:animationDuration]; self.view.frame=frame; [UIViewcommitAnimations]; } [java] view plain copy print ? -(BOOL)textFieldShouldReturn:(UITextField*)textField {//当用户按下ruturn,把焦点从textField移开那么键盘就会消失了 NSTimeIntervalanimationDuration=0.30f; CGRectframe=self.view.frame; frame.origin.y+=216; frame.size.height-=216; self.view.frame=frame; //self.view移回原位置 [UIViewbeginAnimations:@"ResizeView"context:nil]; [UIViewsetAnimationDuration:animationDuration]; self.view.frame=frame; [UIViewcommitAnimations]; [textFieldresignFirstResponder]; } 原文来自:http://blog.csdn.net/iukey/article/details/7242488 本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208763,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码