25、UICollectionView卡片拖拽管理
参考链接
// iOS9以上写法
// 手势监听
private func _setupLongGesture() {
let longGes = UILongPressGestureRecognizer.init(target: self, action: #selector(longPressAction(_:)))
cvTop.addGestureRecognizer(longGes)
}
@objc private func longPressAction(_ sender: UILongPressGestureRecognizer) {
switch sender.state {
case .began:
let path = cvTop.indexPathForItem(at: sender.location(in: cvTop))
if path == nil {
break
}
let cell = cvTop.cellForItem(at: path!)
self.view.bringSubviewToFront(cell!)
cvTop.beginInteractiveMovementForItem(at: path!)
break
case .changed:
cvTop.updateInteractiveMovementTargetPosition(sender.location(in: cvTop))
break
case .ended:
cvTop.endInteractiveMovement()
break
case .possible, .cancelled, .failed:
cvTop.cancelInteractiveMovement()
@unknown default:
cvTop.cancelInteractiveMovement()
break
}
}
24、UILabel固定高度时,文字垂直居中改为顶部对齐参考链接
/// UILabel固定高度时,文字从垂直居中改为顶部对齐
class BMTopicLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
var rect = super.textRect(forBounds: bounds, limitedToNumberOfLines: numberOfLines)
rect.origin.y = bounds.origin.y
return rect
}
override func drawText(in rect: CGRect) {
let rect = textRect(forBounds: rect, limitedToNumberOfLines: numberOfLines)
super.drawText(in: rect)
}
}
// 移动逻辑
func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
if collectionView == cvTop {
return true
}
return false
}
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let m = group0[sourceIndexPath.item]
group0.remove(at: sourceIndexPath.item)
group0.insert(m, at: destinationIndexPath.item)
// 移动结束后刷新
var arr: [BMWristBandCardModel] = []
arr.append(contentsOf: group0)
arr.append(contentsOf: group1)
BMDeviceTool.bm_saveCardList(arr: arr)
if cardEditCloser != nil {
cardEditCloser!()
}
}
23、Xcode15.3打包,Handyjson报错Call parameter type does not match function signature!
解决办法:Xcode 15.3 Archive失败
参考链接
// 在 Pods-Target-HandyJSON-build settings。
// 然后设置Optimization Level为
// None和No Optimization。
升级Xcode15后 打包报错 xxx Command SwiftCompile failed with a nonzero exit code
解决办法: 选中pod 报错的库 Code Generation->Compilation Mode改成和debug一样的 Incremental。
22、打包提交审核报错opencv2, PaddleLite
1、pod ‘OpenCV2’ 默认版本 V4.3.0
2、删除项目源文件opencv2
3、编译报错
'opencv2/highgui/cap_ios.h' file not found ->改为 #import <opencv2/videoio/cap_ios.h>
https://blog.csdn.net/Story51314/article/details/54617451/
opencv2/highgui/ios.h' file not found -> 改为 #include <opencv2/imgcodecs/ios.h>
'opencv2\imgproc\types_c.h' file not found 改为 #include <opencv2/core/types_c.h>
Use of undeclared identifier 'CV_BGR2RGB' 头文件导入 #include <opencv2/imgproc/types_c.h>
4、头文件引入注意事项
其中 一个警告 Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
意思是 让我们在引用这个头文件的时候应该放在所有Apple头文件之前
链接:https://www.jianshu.com/p/ff1a035df84f
5、参考4,调整各个文件目录顺序
6、删除libjpeg.a文件,pod集成DFJPEGTurbo
7、文件结构报错
Invalid bundle structure. The “ShowMe.app/third-party/PaddleLite/lib/libpaddle_api_light_bundled.a” binary file is not permitted. Your app cannot contain standalone executables or libraries, other than a valid CFBundleExecutable of supported bundles.
删除
链接:https://blog.csdn.net/wsyx768/article/details/129073522
21、iOS截图长图代码实现
+ (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView;
+ (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView {
UIImage* image = nil;
UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0.0);
//保存collectionView当前的偏移量
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect saveFrame = scrollView.frame;
//将collectionView的偏移量设置为(0,0)
scrollView.contentOffset = CGPointZero;
scrollView.layer.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
//在当前上下文中渲染出collectionView
[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
//截取当前上下文生成Image
image = UIGraphicsGetImageFromCurrentImageContext();
//恢复collectionView的偏移量
scrollView.contentOffset = savedContentOffset;
scrollView.layer.frame = saveFrame;
UIGraphicsEndImageContext();
if (image != nil) {
return image;
}else {
return nil;
}
}
20、审核中可能被怀疑的问题
1.1.6 - Include false information, features, or misleading metadata.
2.3.0 - Undergo significant concept changes after approval
2.3.1 - Have hidden or undocumented features, including hidden "switches" that redirect to a gambling or lottery website
3.1.1 - Use payment mechanisms other than in-app purchase to unlock features or functionality in the app
3.2.1 - Do not come from the financial institution performing the loan services
4.3.0 - Are a duplicate of another app or are conspicuously similar to another app
5.2.1 - Were not submitted by the legal entity that owns and is responsible for offering any services provided by the app
5.2.3 - Facilitate illegal file sharing or include the ability to save, convert, or download media from third party sources without explicit authorization from those sources
5.3.4 - Do not have the necessary licensing and permissions for all the locations where the app is used
19、注册错误,不允许注册时要求用户填写身份证+姓名等敏感信息。
18、IPV6审核失败解决方案
// app在国内环境登录使用一切正常,审核人员登录时会提示连接失败,报500错误!并且期初错误无法复现。
// 错误复现场景,在手机设置->通用->地区与时间->将国家改为美国,成功复现连接失败错误!
// 配合后台同事调试,发现为语言包配置错误导致连接失败,没有返回任何内容。
17、IPV6审核失败解决方案
App Store ipv6 审核一直被拒绝
错误: iOS审核被拒之 ipv6
阿里云 Ubuntu 支持 IPv6 的完整步骤
16、SDWebImage在4.0之后不再支持加载gif动图,需要单独导入支持gif的库即可。
pod 'SDWebImage/GIF'
// 使用FLAnimatedImageView来代替UIImageView即可加载Gif图片
15、测试安装app时报错“This application does not support this device’s CPU type.”
// 原因:32位的Application已经被苹果淘汰,不再支持安装!
// 解决:项目中找到 Build Settings -> Architectures ,修改为 standard architectures 即可!
14、如何在用户退出时清空单例对象值,并且保证在重新登录时可以新建单例对象?
iOS 单列的创建和销毁
+ (void)qmx_userDealloc {
onceToken = 0;
_instance = nil;
}
// 1. 必须把static dispatch_once_t onceToken; 这个拿到函数体外,成为全局的.
// 2.只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
13、UICollectionView用法补充
// MARK: - 1.header注册方式
// 参数2 在头文件最顶部 header 或 footer
[cv registerClass:[ZXFPhotoAlbumHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID];
// MARK: - 2.显示header
// 需要在布局属性中设置header的size
self.headerReferenceSize = CGSizeMake(self.collectionView.width, 40);
// MARK: - 3.其他
// header类型是继承自 UICollectionReusableView
// 返回视图的方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
ZXFPhotoAlbumHeaderView *headerV = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];
headerV.title = [NSString stringWithFormat:@"这是第 %@ 组", @(indexPath.section).description];
return headerV;
}
12.iOS Crash文件分析
iOS Crash - 分析篇
11.UITextField文本框的光标处理
// 会影响所有光标颜色
[[UITextField appearance] setTintColor:[UIColor blackColor]];
// 单独修改某一个光标颜色
textField.tintColor = [UIColor redColor];
// 不显示光标
textField.tintColor = [UIColor clearColor];
10.控件超出父控件范围无法响应的问题
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//1. 边界情况:不能响应点击事件
BOOL canNotResponseEvent = self.hidden || (self.alpha <= 0.01f) || (self.userInteractionEnabled == NO);
if (canNotResponseEvent) {
return nil;
}
//2. 最后处理 TabBarItems 凸出的部分、添加到 TabBar 上的自定义视图、点击到 TabBar 上的空白区域
UIView *result = [super hitTest:point withEvent:event];
if (result) {
return result;
}
for (UIView *subview in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subview convertPoint:point fromView:self];
result = [subview hitTest:subPoint withEvent:event];
if (result) {
return result;
}
}
return nil;
}
9.WebView问题
问题:使用UIWebView加载链接时,底部总是出现黑色的横条。
解决:设置webView的opaque属性为NO,背景颜色设置clearColor即可。
8.友盟分享集成问题
集成选择了微信、QQ、新浪微博。
问题:在弹出的分享面板中微信始终不能出现。
解决:将完整的微信SDK,切换为精简版的微信分享SDK,界面正常展示
7.字体加粗及倾斜
ios 字体类型设置 倾斜加粗等
字体加粗
loginLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
字体加粗并且倾斜
loginLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];
6.调整文字间距和行距
iOS开发小知识之改变UIlabel的行间距和字间距
#import <UIKit/UIKit.h>
@interface UILabel (ChangeLineSpaceAndWordSpace)
/**
* 改变行间距
*/
+ (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space;
/**
* 改变字间距
*/
+ (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space;
/**
* 改变行间距和字间距
*/
+ (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace;
@end
#import "UILabel+ChangeLineSpaceAndWordSpace.h"
@implementation UILabel (ChangeLineSpaceAndWordSpace)
+ (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {
NSString *labelText = label.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:space];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
label.attributedText = attributedString;
[label sizeToFit];
}
+ (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space {
NSString *labelText = label.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(space)}];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
label.attributedText = attributedString;
[label sizeToFit];
}
+ (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace {
NSString *labelText = label.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(wordSpace)}];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpace];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
label.attributedText = attributedString;
[label sizeToFit];
}
@end
1.cornerstone上传默认忽略.a库文件,导致项目编译报错!
解决:设置cornerstone的偏好设置,不要忽略.a库文件即可!
cornerstone ->preferences->Subversion->关闭 Use default global ignores -> 删除 *a选项!
2.环信推送测试收不到推送消息
【原来配置环信apns就这么简单】内含各种问题点详讲
-> 1.测试证书的软件 Ease APNs Provider 可以测试生成的cer推送证书是否有问题
-> 2.按照文档进行排查
错误:上传的测试证书,环境选择成了开发环境!
解决:重新上传证书,正确选择环境即可
3.UISlider控件触发值改变事件比较频繁!
UISlider *slider = [[UISlider alloc] init];
UIImage *img = [UIImage imageNamed:@"fontchange"];
// 只在手指抬起时触发一次值改变事件
slider.continuous = NO;
[slider setThumbImage:img forState:UIControlStateNormal];
4.”A valid provisioning profile for this executable was not found“
从描述上可以看到说:对于可执行provisioning profile 没有被找到。所以网上有很多答案是说你provisioning profile没有被找到,需要重新导入之类的。
http://blog.sina.com.cn/s/blog_71715bf8010164z5.html
但是我碰到的原因是我在Project中将Code Signing Identity中将其设置成了iPhone Develop,但是在Target中的Code Signing Identity并没有自动切换过来,我发现在Target中的Code Signing Identity还是我之前的设的iPhone Distribution,
所以看到这里就知道了,iPhone Distribution 的provisioning profile肯定是不能运行的,所以把Target中的Code Signing Identity也设置成iPhone Develop就ok了,这样一切都说的通了,唯一不合理的就是在Project切换Code Signing Identity并编译,但xCode没有自动将编译后的Target设置成和Project中的一致
5.上传错误
提交审核之前,如果需要更新构建版本,只需要更新CFBundleVersion就可以,不需要更改版本号!
解决了第一个错误就没问题了,原因是环信SDK中支持了X86_64
http://docs.easemob.com/im/300iosclientintegration/20iossdkimport