iOS开发 日常笔记

1   区分tabbar和nav文字修改
self.navigationItem.titleView = nil; ----->导航栏view修改   
self.navigationItem.title = THLocalized(@"disconnect");--->单独导航栏文字修改  
self.title     --->导航栏+tabbar  文字修改

2.imageView 添加动画效果

  NSArray *images = [NSArray arrayWithObjects:

                       [UIImage imageNamed:@"paiZhao"],

                       [UIImage imageNamed:@"beginLuXiang"], nil];

self.takePhotoImg.animationImages = images; 
动画时间     self.takePhotoImg.animationDuration = 0.8;
是否重复  0为循环  self.takePhotoImg.animationRepeatCount = 1;
[self.takePhotoImg startAnimating];
[self.takePhotoImg stopAnimating];

3.线程问题

    NSLog(@"1111111111");
dispatch_queue_t queue = dispatch_get_global_queue(0.5, 0);

        dispatch_async(queue, ^(void) {

            NSLog(@"33333333");

        dispatch_async(dispatch_get_main_queue(), ^(void) {

                NSLog(@"44444444");

                });

            });

NSLog(@"22222222");

4.   代码只执行一次
static dispatch_once_t disOnce;
            
            dispatch_once(&disOnce,^ {
                
            FsDoorBellStartSpeakingUa(1,0);
                
            });

5.判断字典是否为nil
  if (dict != nil && ([dict isKindOfClass:[NSDictionary class]] == YES))

6.根据 文字数量来改变label字体大小
[_nameLabel setAdjustsFontSizeToFitWidth:YES];

7.命名规范

//判断是否含有非法字符

    NSString *str =@"^[A-Za-z0-9\\u4e00-\u9fa5]+$";

    NSPredicate* emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", str];
//判断中英文
int a =[nick characterAtIndex:i];

  if( a >0x4e00 && a <0x9fff)//中文

 

8.  UISlider监听滑动结束状态
[_bufferSlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];//变化
       
  [_bufferSlider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];//开始
 [_bufferSlider addTarget:self action:@selector(sliderTouchUpInSide:) forControlEvents:UIControlEventTouchUpInside];//结束
- (void)sliderTouchDown:(UISlider *)sender{}


9.更改cell的选中格式

 UIImage *image = [UIImage imageNamed:@"door_sel"];
    if (cell.accessoryType == UITableViewCellAccessoryNone)
    {
        image = [UIImage imageNamed:@"door_nosel"];
        
    }
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0.0,0.0,image.size.width,image.size.height);
    button.frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal];
    button.backgroundColor = [UIColor clearColor];
    cell.accessoryView = button;

10.[UIImage imageNamed:@""]和[UIImage imageWithContentsOfFile]的使用

[UIImage imageNamed:@""]分配的图像系统会放到cache里面。而关于cache管理的规则就没有明确的介绍。
由此看来[UIImage imageNamed:]只适合与UI界面中小的贴图的读取,而一些比较大的资源文件应该尽量避免使用这个接口。

可以通过直接读取文件路径[UIImage imageWithContentsOfFile]解决掉这个问题.

11.
栈中存在的界面:
跳转至指定页面

NSArray*temArray = self.navigationController.viewControllers;

TestListViewController *test = [[TestListView Controlleralloc] init];

for(UIViewController *temVCintemArray)

{

      if([temVC isKindOfClass:[test class]])

      {

      [self.navigationController popToViewController:temVC animated:YES];

      }

}

跨页面跳转至相关页面方法:

指定跳转页面设置对应 tag 值:

self.view.tag = 20000;//tag(需要跳转的当前 VC)

跳转事件 VC 所需实现的方法:

for (int i = 0; i < [self.navigationController viewControllers].count; i++) {

      if ([[self.navigationController viewControllers] objectAtIndex:i].view.tag == 20000) {

            navTag = i;

      } else if ([[self.navigationController viewControllers] objectAtIndex:i].view.tag == 30000) {

            navTag = i;

      } else if ([[self.navigationController viewControllers] objectAtIndex:i].view.tag == 10000) {

            navTag = i;

      }

}

[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:navTag] animated:YES];

栈中不存在的界面:
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];

                    for (int i = 0; i < viewControllers.count; i++){

                        id vc = viewControllers[i];

                        //1.找到要插入界面的前一个界面

                        if ([vc isKindOfClass:[DBDeviceListController class]]){

                            WatchMainController *insertVC = [[WatchMainController alloc] init];

                            //2.插入到界面栈中

                            [viewControllers insertObject:insertVC atIndex:i + 1];

                            //3.更新界面栈

                            [self.navigationController setViewControllers:viewControllers animated:NO];

                            insertVC.device = device;

                            //4.跳转到指定界面

                            [self.navigationController popToViewController:insertVC animated:YES];

                              return;

                        }

  }

NSObject 固定界面跳转指定界面

    UITabBarController *tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;           UINavigationController *nav = (UINavigationController *)tabBarVc.viewControllers[tabBarVc.selectedIndex];

    [nav pushViewController:detailVC animated:YES];

NSObject 任意界面跳转指定界面

1.    UITabBarController *tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;

    switch (tabBarVc.selectedIndex) {}

2.[[NSNotificationCenter defaultCenter]postNotificationName:@"Y1PushRecentUsersLock" object:nil userInfo:nil];

3.self.tabBarController.selectedIndex = 1;

    [self.navigationController popToRootViewControllerAnimated:YES];

 

12.单选
1.@property (assign, nonatomic) NSIndexPath *selIndex;//单选,当前选中的行
2.如果cell有复用cellForRowAtIndexPath方法里面加上if (_selIndex == indexPath) 判断
3.didSelectRowAtIndexPath方法里面 
//之前选中的,取消选择
DBTimeTableCell *selTimeCell = (DBTimeTableCell*)[tableView cellForRowAtIndexPath:_selIndex];
[selTimeCell.timeSelBtn setImage:[UIImage imageNamed:@"door-noselect"] forState:UIControlStateNormal];
//记录当前选中的位置索引 
_selIndex = indexPath;
DBTimeTableCell *timeCell = (DBTimeTableCell*)[_tableView cellForRowAtIndexPath:indexPath];
[timeCell.timeSelBtn setImage:[UIImage imageNamed:@"door-select"] forState:UIControlStateNormal];

13.view盖住navigationBar和tabBar

[self.tabBarController.view addSubview:_blackBackView]
[self.navigationController.view addSubview:_blackBackView];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值