iOS开发中遇到的小问题汇总(持续更新)

1、使用UIWebView加载网页时,当页面中有视频播放时,调用系统的播放器进行播放,但是点击全屏播放然后返回时,发现状态栏少了一部分,这里需要对退出全屏进行监听,具体代码如下:


//监听UIWindow隐藏

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(endFullScreen) name:UIWindowDidBecomeHiddenNotification object:nil];

-(void)endFullScreen{

    if ([UIApplication sharedApplication].statusBarHidden) {

        [[UIApplication sharedApplication] setStatusBarHidden:false withAnimation:false];

    }

}

别忘记在后面取消通知

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeHiddenNotification object:nil];
}

2、更新Xcode10.3后运行没有可选择的模拟器,在真机上运行报错,解决办法:
Kill all simulator processes

$ sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService

Set the correct Xcode path

$ sudo xcode-select -s  /Applications/Xcode.app/Contents/Developer

If that doesn’t work, reset all simulators

$ xcrun simctl erase all

3、在iPhone X以上的设备使用MJRefresh时上拉的状态一直存在,可以在AppDelegate通过添加

if (@available(iOS 11.0, *)) {
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIApplicationBackgroundFetchIntervalNever];
        [[UITableView appearance] setEstimatedRowHeight:0.f];
        [[UITableView appearance] setEstimatedSectionHeaderHeight:0.f];
        [[UITableView appearance] setEstimatedSectionFooterHeight:0.f];
    }

4、iOS拨打电话 由于最近APP审核提示会停止使用UIWebview API,所以修改了以前使用UIWebview打电话的方式

/**
  * 拨打电话,弹出提示,拨打完电话回到原来的应用
  * 注意这里是 telprompt://
 */
NSString *phoneStr = [NSString stringWithFormat:@"telprompt://%@",self.model.mobile];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneStr]];

5、类似微博主页、简书主页等效果。多页面嵌套,既可以上下滑动,也可以左右滑动切换页面。支持HeaderView悬浮、支持下拉刷新、上拉加载更多。https://github.com/pujiaxin33/JXPagingView 先保存一下 有时间学习学习
6、UIWebView打开相册或者预览时顶部会有遮挡,需要适配iOS11

if (@available(iOS 11, *)) {
        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
    }

如果是使用UIImagePickerController,可以通过去除毛玻璃效果,_picker.navigationBar.translucent = NO;
7、UITextField实时监测内容有两种方法:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString *str = [textField.text stringByReplacingCharactersInRange:range withString:string];
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    NSLog(@"%@", str );
    return YES;
}

或者

[textField addTarget:self action:@selector(textFieldEditChanged:) forControlEvents:UIControlEventEditingChanged];

代理方法

- (void)textFieldEditChanged:(UITextField *)textField
{
    NSLog(@"textfield.text %@",textField.text);
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,135评论 1 32
  • 来到苹果姐姐《不租房的606天》签售会现场,收获了很多金句,也成为了自己勇敢直前的风向标,感恩分享,感恩遇见...
    艾欣老师阅读 335评论 0 1
  • Date: 2018/8/12 感恩金色愛之流從四面八方湧來:感恩宇宙這麼愛我,天天有人給我送錢、讓我天天都進帳、...
    采灵22阅读 209评论 0 3
  • 叶渐黄、奈秋至, 猝不及、相思意。
    无相灵雅阅读 172评论 0 0
  • 你可能不知道,这姑娘是你。 春风十里, 微风拂动,惬意的时光里,姑娘你永远那样美,我说不出,说不出时光...
    凉笙520阅读 214评论 2 6