项目知识点.Part1

1. storyboard中添加scrollview:

先添加scrollView,进行约束

添加View 进行约束 相对于scrollView

如果水平滑动:设置vertically in Container   竖直方向滑动:Horizontally in Container

将View的宽度以scroView为基准  改变倍数

2. 类似于音乐播放器中的图片旋转:定时器

在M_PI前面添加负号  可实现反方向转

1>  masksToBounds 允许修改layout里的属性

[self.MusicImageView layoutIfNeeded]: 当需要改变layout的时候,调用

第一种旋转:  比较麻烦 还得设置current值在不断更新:

// 设置图片为圆形:
    // 修改layout前 先将masksToBounds设置为YES
    [self.MusicImageView layoutIfNeeded];    
    self.imageDetail.layer.masksToBounds = YES;
    self.imageDetail.layer.cornerRadius = self.imageDetail.frame.size.width/2;
    
    [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(rotateAction) userInfo:nil repeats:YES];
 // 将定时器加到runloop中
    [[NSRunLoop currentRunLoop] addTimer:time forMode:NSRunLoopCommonModes];
- (void)rotateAction {
    current += 0.001;
    CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI * current);
    self.imageDetail.transform = transform;
    
}

 第二种更新:不需要设置其他变量实时更新

在block中:

runLoop:子线程中就关闭了

滑动页面时不会因为优先级的问题 影响图片转动

- (void)play {
    [self.avPlayer play];
    self.isPlay = YES;
    // 定时器使用方法:
    /*
     每隔TimeInterval0.1秒调用这个方法
     */
    if (self.timer == nil) {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(playTimer) userInfo:nil repeats:YES];
    }
    // 将定时器加到runloop中
    [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    
}

block调用中:

self.MusicImageView.transform = CGAffineTransformRotate(self.MusicImageView.transform, M_PI / 180);

2> 定时器:

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(playTimer) userInfo:nil repeats:YES] :

每隔TimeInterval秒调用这个方法

定时器销毁:

[self.timer invalidate];

安全写法:

创建前判断是否为空

销毁前判断是否存在 

// 创建
if (self.timer == nil) {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(playTimer) userInfo:nil repeats:YES];
    }


// 销毁
if (self.timer) {
        // 销毁定时器
        [self.timer invalidate];
        // 手动置空:
        self.timer = nil;
    } 

3. scrollView:

约束了scroll只能在竖直方向滑动  下面这个属性为YES时 scrollView在水平方向上也可以滑动 只有改成NO  才只能在竖直方向滑动

// 自动添加了上下64 设置为NO 取消viewController自动调整
    self.automaticallyAdjustsScrollViewInsets = NO;

4. __weak   __block 修饰self 防止循环引用:

在本类调用其他类中的block,使用self不会造成循环引用

5. block使用:

block声明:

@property (copy,nonatomic) void (^block)(NSString *);

block实现:

实现的内容暂时不走 先把block实现的代码块存起来

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    TwoViewController *twoVC =(TwoViewController *) segue.destinationViewController;
    // block实现
    twoVC.block = ^(NSString *str) {
        self.label.text = str;
    };
}

block调用:

当调用block的时候(安全写法:调用前先判断block是否存在):self.block(self.textField.text)---->开始执行上述存起来的block实现代码块 将调用传进来的值赋给实现代码

- (IBAction)popViewController:(UIButton *)sender {
    // block调用:
    if (self.block) {
        self.block(self.textField.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

6.

1> 设置pch文件 :Prefix Header

绝对路径:拷贝到其他电脑就不好用了 /Users/lanou3g/Documents/项目期/MusicTextOne/Class/Help/PrefixHeader.pch

相对路径:$(SRCROOT)/Class/Help/PrefixHeader.pch

2> componentsSeparatedByString:根据某个字符串分割, 返回值是数组

7. 多线程实现网络请求 数据解析:

+ (void)ResquestDataURL:(NSString *)URLStr block:(void(^)(NSArray *))block {
    
    // 子线程请求数据
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:URLStr]];// 获取数据
        // 创建model数组
        NSMutableArray *modelArray =[NSMutableArray array];
        for (NSDictionary *dic in array) {
            MusicModel *model = [[MusicModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [RequestData musicModelRequest:model];
            [modelArray addObject:model];
        }
        
        // 主线程返回数据
        dispatch_async(dispatch_get_main_queue(), ^{
            // 在主线程返回数据
            if (block) {
                NSLog(@"block = %@", block);
                block(modelArray);
            }
        });
    });
//    NSLog(@"哈哈哈哈哈哈");
}

 8. 获取storyboard中的控制器方法:

UIStoryboard *storyB = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    ListenDetailViewController *DetailVC = [storyB instantiateViewControllerWithIdentifier:@"detail_id"];

 9. 获取自定义UITableViewCell中的按钮所在的cell

这个点也很重要哦 ~

-(IBAction)button:(id)sender{  
    UIButton* button = (UIButton*)sender;   
    UITableViewCell* buttonCell = (UITableViewCell*)[sender superview];   
    NSUInteger row = [[tableView indexPathForCell:buttonCell]row];  
}

 10.iOS NSString 和NSData 转换

格式转换部分的原博:http://blog.csdn.net/bailu66/article/details/7665357 

(除格式转换的其他内容均为本人所写)

NSString 转换成NSData 对象

NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding];

NSData 转换成NSString对象

NSData * data;
NSString *result = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];

NSData 转换成char*

NSData *data;
char *test=[data bytes];

char* 转换成NSData对象

byte* tempData = malloc(sizeof(byte)*16);
NSData *content=[NSData dataWithBytes:tempData length:16];

哈哈哈

原文地址:https://www.cnblogs.com/Evelyn-zn/p/4971969.html