iOS

iOS小技巧

收集各种iOS小技巧

Posted by 任天恒 on December 7, 2015
  • iOS中收起键盘

    在UIViewController中收起键盘,除了调用相应控件的resignFirstResponder方法外,还有另外三种方法:

    1.重载UIViewController中的touchesBegin方法,然后在里面执行[self.view endEditing:YES];这样单击UIViewController的任意地方,就可以收起键盘。

    [self.view endEditing:YES];
    

    2.直接执行 [[UIApplication sharedApplication]sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 用于在获得当前UIViewController比较困难的时候用。

    [[UIApplication sharedApplication]sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    

    3.直接 [[[UIApplication sharedApplication]keyWindow]endEditing:YES];

    [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
    
  • 设置应用系统内的系统控件语言

    打开工程的info.plist文件,在文件中增加如下内容:

    <key>CFBundleLocalization</key>
    <array>
      <string>zh_CN</string>
      <string>en</string>
    </array>
    
  • javaScript文件设置调整

    JavaScript的js后缀的文件默认被拖动到工程中后,是在编译列表中,而不是资源列表中。你需要手工地调整其位置,否则它就不能打包到ipa文件中。

    这应该是Xcode的一个长期的bug,js文件并不需要编译。做混合开发的新手很容易在第一次尝试的时候被这个问题困扰。

    解决方法:

    手工将这个js文件从Compile Source移动到Copy Boundle Resources

  • 删除scrollView中的所有视图

    假设你的UIScrollView 是scrollView。

    [scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
  • iOS模拟器上键盘显示(不显示)

    1、选中模拟器,在屏幕上方的菜单中找到Hardware->Keyboard 2、直接快捷键shift+command+k