1:使用@protocol实现delegate和datasource模式

#import <UIKit/UIKit.h>

@protocol MyViewDataSource,MyViewDelegate;

@interface myView : UIView<UIAlertViewDelegate>

@property(nonatomic,assign)id<MyViewDelegate> myViewDelegate;

@property(nonatomic,assign)id<MyViewDataSource> myViewDataSource;

-(void)myShowAlert;

@end

@protocol MyViewDelegate <NSObject>

@optional

-(void)alertDidPop:(myView *)myView;

-(void)alertConfirmShow:(myView *)myView clickedButtonAtIndex:(NSInteger)buttonIndex;

@end

@protocol MyViewDataSource <NSObject>

@optional

-(NSString *)textOfAlert:(myView *)myView;

@required

- (NSUInteger)numberOfItemsInMyView:(myView *)myView;

@required

@end
#import "myView.h"

@implementation myView

-(void)myShowAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"测试实例"
message:@"message"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",nil];
alert.message = [self.myViewDataSource textOfAlert:self];
[alert show];
} - (void)didPresentAlertView:(UIAlertView *)alertView
{
[self.myViewDelegate alertDidPop:self];
} -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self.myViewDelegate alertConfirmShow:self clickedButtonAtIndex:buttonIndex];
} @end

使用方式:

#import "myView.h"

@interface ViewController ()<MyViewDataSource,MyViewDelegate>

@end
- (void)viewDidLoad {
[super viewDidLoad]; myView *myVw = [[myView alloc]initWithFrame:CGRectMake(, , , )];
myVw.myViewDataSource = self;
myVw.myViewDelegate = self;
[self.view addSubview:myVw];
[myVw myShowAlert];
}
代理实现的方法:

- (void)alertDidPop:(UIView *)myView
{
myView.backgroundColor = [UIColor yellowColor];
} -(NSString *)textOfAlert:(myView *)myView
{
return @"信息";
} -(void)alertConfirmShow:(myView *)myView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"你选中了%d",buttonIndex);
}

2:动画 UIView animateWithDuration 使用详解

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

duration为动画持续的时间。animations为动画效果的代码块

可设动作属性:

  • frame
  • bounds
  • center
  • transform
  • alpha
  • backgroundColor
  • contentStretch

例如一个视图淡出屏幕,另外一个视图出现的代码

[UIView animateWithDuration:1.0 animations:^{
firstView.alpha = 0.0;
secondView.alpha = 1.0;
}];

连续动画(可以在completion代码块中添加动画):

[UIView animateWithDuration:2.0
animations:^{
oldImageView.alpha = 0.0;
newImageView.alpha = 1.0;
//imageView.center = CGPointMake(500.0, 512.0);
}
completion:^(BOOL finished){
[UIView animateWithDuration:4.0
animations:^{
newImageView.center = CGPointMake(500.0, 512.0);
}];
}];

从上往下一个动作(默认是左上角,把要改变的值放在animations里):

-(UIView *)myView
{
if (!_myView) {
_myView=[[UIView alloc]initWithFrame:CGRectZero];
_myView.backgroundColor=[UIColor redColor];
}
return _myView;
} - (IBAction)BtnAction:(id)sender {
self.myView.frame = CGRectMake(,, , );
[self.view addSubview:self.myView];
[UIView animateWithDuration:0.3 animations:^{
self.myView.backgroundColor=[UIColor redColor];
self.myView.frame = CGRectMake(,, , ); } completion:^(BOOL finished) { }];
}

3:UIView 的旋转和缩放

 label.transform = CGAffineTransformMakeRotation( *M_PI / 180.0);

//顺时针旋转 90度

 label.transform = CGAffineTransformMakeRotation( *M_PI / 180.0);

//顺时针 旋转180度

 label.transform = CGAffineTransformMakeRotation( *M_PI / 180.0);

//顺时针旋转270度

CGAffineTransform transform = label.transform;

transform = CGAffineTransformScale(transform, ,0.5);//前面的2表示横向放大2倍,后边的0.5表示纵向缩小一半  

label.transform = transform;

4:加载歌词的代码实例

[ti:伤痕]
[ar:曾敏杰]
[al:]
[by:]
[offset:]
[:00.11]伤痕 (Live) - 曾敏杰
[:01.58]词:李宗盛
[:02.41]曲:李宗盛
[:03.28]键盘:刘卓/李海郡
[:04.78]吉他:高飞/金天
[:06.20]贝司:李九君
[:07.29]鼓手:卢炜
[:08.17]乐队总监:刘卓
[:09.43]音响总监:金少刚
[:11.01]
[:22.75]夜已深 还有什么人
[:28.21]让你这样醒着数伤痕
[:32.28]
[:33.09]为何临睡前会想要留一盏灯
[:38.04]你若不肯说 我就不问
[:42.07]
[:42.74]只是你现在不得不承认
[:47.35]
[:47.93]爱情有时候是一种沉沦

歌词都是以lrc的文件内容,可以进行加载,然后对它进行处理;

@implementation WPFLyricParser

+ (NSArray *)parserLyricWithFileName:(NSString *)fileName {

    // 根据文件名称获取文件地址
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:nil]; // 根据文件地址获取转化后的总体的字符串
NSString *lyricStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL]; // 将歌词总体字符串按行拆分开,每句都作为一个数组元素存放到数组中
NSArray *lineStrs = [lyricStr componentsSeparatedByString:@"\n"]; // 设置歌词时间正则表达式格式
NSString *pattern = @"\\[[0-9]{2}:[0-9]{2}.[0-9]{2}\\]";
NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:pattern options: error:NULL]; // 创建可变数组存放歌词模型
NSMutableArray *lyrics = [NSMutableArray array]; // 遍历歌词字符串数组
for (NSString *lineStr in lineStrs) { NSArray *results = [reg matchesInString:lineStr options: range:NSMakeRange(, lineStr.length)]; // 歌词内容
NSTextCheckingResult *lastResult = [results lastObject];
NSString *content = [lineStr substringFromIndex:lastResult.range.location + lastResult.range.length]; // 每一个结果的range
for (NSTextCheckingResult *result in results) { NSString *time = [lineStr substringWithRange:result.range]; #warning 对于 NSDateFormatter 类似的重大开小对象,最好使用单例管理
NSDateFormatter *formatter = [NSDateFormatter sharedDateFormatter];
formatter.dateFormat = @"[mm:ss.SS]";
NSDate *timeDate = [formatter dateFromString:time];
NSDate *initDate = [formatter dateFromString:@"[00:00.00]"]; // 创建模型
WPFLyric *lyric = [[WPFLyric alloc] init];
lyric.content = content;
// 歌词的开始时间
lyric.time = [timeDate timeIntervalSinceDate:initDate]; // 将歌词对象添加到模型数组汇总
[lyrics addObject:lyric];
}
} // 按照时间正序排序
NSSortDescriptor *sortDes = [NSSortDescriptor sortDescriptorWithKey:@"time" ascending:YES];
[lyrics sortUsingDescriptors:@[sortDes]]; return lyrics;
} @end

 5:UIWebView加载POST请求

 NSURL *url = [NSURL URLWithString: @"http://your_url.com"];
NSString *body = [NSString stringWithFormat: @"arg1=%@&arg2=%@", @"val1",@"val2"]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];

最新文章

  1. EC笔记:第4部分:19、设计class犹如设计type
  2. 配置BUG-Linux系统下ssh登陆很慢的解决办法
  3. 使用UIKit制作卡牌游戏(二)ios游戏篇
  4. JAVA输入一个整数,求出其所有质因数
  5. spring mvc 的Controller类默认Scope是单例(singleton)的
  6. awk处理之案例四:sort加awk来过滤文本
  7. linux常用指令(飞天云)
  8. 对于方法 String.Contains,只支持可在客户端上求值的参数。
  9. 16-GDBT(MART) 迭代决策树入门教程 | 简介
  10. WPF 自定义数字文本框:NumericBox
  11. 基于WCF的RESTFul WebAPI如何对传输内容实现压缩
  12. java 并发多线程异步
  13. nginx的配置服务器集群,负载均衡
  14. Service详解
  15. 【hibernate 初探】之 关系映射,ORM
  16. Who do you want to be bad? (谁会是坏人?)人工智能机器小爱的问话
  17. mysql插入记录INSERT与多表更新
  18. app:processDebugResources
  19. 【大数据系列】MapReduce示例一年之内的最高气温
  20. ElasticSearch—分页查询

热门文章

  1. (第六天)DOM
  2. 【技巧篇】解决悬浮的&lt;header&gt;、&lt;footer&gt;遮挡内容的处理技巧
  3. 5分钟用Spring4 搭建一个REST WebService
  4. Hawk 数据抓取工具 使用说明(二)
  5. 窥探Swift编程之在Playground上尽情的玩耍
  6. 缓存Cookie、session、localStorage的区别
  7. 关于 android 的 view.getLeft(), getRight(), getTop(), getBottom() 的一些疑惑(坑)解答
  8. CocoaPods 安装 使用
  9. cocopads命令行
  10. Html标签列表【转】