美文网首页
iOS零散知识点总结

iOS零散知识点总结

作者: 顺7zi燃 | 来源:发表于2019-01-10 18:11 被阅读0次

1.设置屏幕常亮

[UIApplication sharedApplication].idleTimerDisabled = YES; 

2.竖屏应用中部分界面强制转横屏

  • AppDelegate 类
//强制横屏/竖屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
  if (self.allowLandscapeLeft) {
      return UIInterfaceOrientationMaskLandscape;
  }
  return UIInterfaceOrientationMaskPortrait;
}
  • 某个类需要横竖屏切换,在类中实现
// 强制横屏    
-(void)forceOrientationLandscape{
  //加上代理类里的方法,旋转屏幕可以达到强制横屏的效果
  AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  appDelegate.allowLandscapeLeft = YES;
  //强制旋转成全屏
   NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationLandscapeLeft];
  [[UIDevice currentDevice]setValue:value forKey:@"orientation"];
  [UIViewController attemptRotationToDeviceOrientation];
 }


 // 强制竖屏
-(void)forceOrientationPortrait{
  AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  appDelegate.allowLandscapeLeft = NO;
//强制旋转成竖屏
  NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait];
  [[UIDevice currentDevice]setValue:value forKey:@"orientation"];
  [UIViewController attemptRotationToDeviceOrientation];
}

3.键盘处理神器 IQKeyboardManager

  • 在 AppDelegate 中设置全局属性
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量

  keyboardManager.enable = YES; // 控制整个功能是否启用

  keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘

  keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义

  keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时,可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框

  keyboardManager.enableAutoToolbar = YES; // 控制是否显示键盘上的工具条

  keyboardManager.shouldShowTextFieldPlaceholder = YES; // 是否显示占位文字

  keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体

  keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离

  return YES;
}
  • 若某个类不需要使用 IQKeyboardManager,可以在这个类中这样设置
- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
   [IQKeyboardManager sharedManager].enable = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
  [super viewWillDisappear:animated]; 
  [IQKeyboardManager sharedManager].enable = YES;
}

4.权限设置及提示

<key>NSCameraUsageDescription</key>
<string>此App会在上传照片、录制视频或直播时访问您的相机权限,是否允许app使用相机</string>
<key>NSMicrophoneUsageDescription</key>
<string>此App会在录制视频或音频时访问您的麦克风权限,是否允许app使用麦克风</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>此App需要您的同意,才能保存图片到您的相册</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>此App会在上传图片时访问您的相册权限,是否允许app使用相册</string>
  1. 补全UITableViewCell分隔线左侧缺失的方式
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{ 
  if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { 
    [cell setLayoutMargins:UIEdgeInsetsZero];
  } 
  if ([cell respondsToSelector:@selector(setSeparatorInset:)]){ 
      [cell setSeparatorInset:UIEdgeInsetsZero];
   }
 }

6.在 有navigationBar 的界面 上 覆盖 一个全屏的半透的VC

ShareVC *shareVc = [ShareVC new];
self.definesPresentationContext = YES;
shareVc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:shareVc animated:YES completion:nil];

如果A present B设置 A.definesPresentationContext = YES; B.modalPresentationStyle = UIModalPresentationOverCurrentContext; B.view 是半透明的,然后让A 把B present 出来,就是半透明的

  • UIModalPresentationStyle
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
    UIModalPresentationFullScreen = 0,
    UIModalPresentationPageSheet ,
    UIModalPresentationFormSheet ,
    UIModalPresentationCurrentContext ,
    UIModalPresentationCustom ,
    UIModalPresentationOverFullScreen ,
    UIModalPresentationOverCurrentContext ,
    UIModalPresentationPopover ,
    UIModalPresentationNone  = -1,         
};
  1. 创建HTTP请求报错
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

8.![配置pch文件@2x.png]

$(SRCROOT)/$(PROJECT_NAME)/PrefixHeader.pch
配置pch文件@2x.png

9.UICollectionView内容横向滚动

self.collectionView.delegate = self;
self.collectionView.dataSource = self;
// 不满足一屏不滚动
self.collectionView.alwaysBounceHorizontal = NO;
// 横向滚动
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView.collectionViewLayout = layout;
    
self.collectionView.showsHorizontalScrollIndicator = NO;
    
[self.collectionView registerNib:[UINib nibWithNibName:@"xxCell" bundle:nil] forCellWithReuseIdentifier:@"xxCell"];
  1. 新上传到App Store里的构建版本显示 缺少合规证明
  • Info.plist 文件中添加下面代码
<key>ITSAppUsesNonExemptEncryption</key><false/>

相关文章

网友评论

      本文标题:iOS零散知识点总结

      本文链接:https://www.haomeiwen.com/subject/imrgrqtx.html