开发中常见的bug/及项目解说

来源:互联网 发布:股票交易软件制作公司 编辑:程序博客网 时间:2024/05/17 09:12
1.添加点按手势:
//添加一个点按手势
       
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tap)];
       
//开启图片可以进行交互
        adImageView.
userInteractionEnabled=YES;
        [adImageViewaddGestureRecognizer:tap];

2.点击cell进行页面跳转:
#pragma mark - UICollectionViewDelegate
//点击cell就会调用
- (
void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
{
   
// 获取对应模型
   
XMGSquareItem *item = _squareItems[indexPath.row];
   
   
// 只要不是http,就跳转到网页
   
if (![item.urlhasPrefix:@"http"])return;
   
   
// 跳转到网页
   
// 展示WKWebView
   
XMGWebViewController *webVc = [[XMGWebViewControlleralloc]init];
    webVc.
url= [NSURLURLWithString:item.url];
    [self.navigationControllerpushViewController:webVcanimated:YES];
与push相反的是 [selfpopViewControllerAnimated:YES];

3.:设置全屏滑动返回功能,pan:滑动返回功能
   //1.添加自己的滑动手势,用系统的target= <(action=handleNavigationTransition:方法实现滑动返回
   
id target = self.interactivePopGestureRecognizer.delegate;
   
//2.创建手势
   
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc]initWithTarget:targetaction:@selector(handleNavigationTransition:)];
   
//3.将手势添加到当前控制器中
    [
self.viewaddGestureRecognizer:pan];
   
//4.去掉系统边缘滑动手势
   
self.interactivePopGestureRecognizer.enabled=NO;
   
//5.设置当前控制器为手势代理
    pan.delegate=self;

//每次触发手势就会判断是否接受手势
- (
BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch{
   
//只有非根控制器才允许滑动,判断当前是不是跟控制器,如果不是允许滑动
   
return self.childViewControllers.count>1;

}

4.解决tabbar条按钮图片和文字渲染问题:
1>解决文字渲染
 /*
     1.appearance
获取全局UItabBar外观,在开发中尽量不要使用appearance,而是要使用appearanceWhenContainedIn:表示获取哪个类下面的导航条
     2.
导航条标题字体的大小由导航条决定
     */

   
UITabBarItem *item = [UITabBarItemappearanceWhenContainedIn:self,nil];
   
//1.创建字典
   
NSMutableDictionary *attr = [NSMutableDictionarydictionary];
   
//用字典描述文本属性,设置其颜色为黑色
    attr[
NSForegroundColorAttributeName] = [UIColorblackColor];
   
//设置选中状态下的文字颜色为黑色
    [item
setTitleTextAttributes:attrforState:UIControlStateSelected];
   
   
//在正常状态下设置字条大小,只有在正常状态下才能设置字体大小
   
//创建字典用来描述文本属性
   
NSMutableDictionary *attrNor = [NSMutableDictionarydictionary];
   
//设置字体大小
    attrNor[
NSFontAttributeName] = [UIFontsystemFontOfSize:14];
   
//在正常状态下设置字体为16号字体
    [item
setTitleTextAttributes:attrNorforState:UIControlStateNormal];
}
2>解决图片渲染:给图片添加个分类方法

#import"UIImage+Image.h"

@implementationUIImage (Image)
//实现不要加载渲染图片的方法
+(
UIImage*)imageWithOriginalRenderingMode:(NSString*)imageName{

   
//1.创建图片
   
UIImage *image = [UIImageimageNamed:imageName];
   
//返回选中的图片
   
return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
   
}
@end

5.解决xib拉伸中的bug:
01-当控件从xib加载,发现莫名其妙的不好使,怎么解决
答:// bug:如果发现一个控件从xib加载出来,显示的效果跟xib不一样,就可能被拉伸,取消这个控件不要拉伸
   //理论:任何一个view,都会有额外拉伸属性
   self.autoresizingMask=UIViewAutoresizingNone;

6.全局滑动手势/02进阶/彩票/02day/12-滑动移除控制器全屏实现&解决bug(添加在view上)
tableview左右滑动,让tableview添加到collectionView的cell上,滑动collectionView的cell实现
性能优化:
使用collectionView的好处是,其可以循环利用解决渲染,当一个view出现在屏幕上时就会渲染占用内存降低性能,当用collectionView时,当一个新的cell从缓存池出去时,会将对应的子控制器的view添加到cell上,同时删除之前子控制器的view降低内存,并将之前的cell放入缓存池中

7.移动下划线滚动位置:
 //移动下划线的位置
    [
UIViewanimateWithDuration:0.25animations:^{
       
       
_underLineView.xmg_centetX= titleButton.xmg_centetX;
    }];
}
0 0