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];

IOS开发基础知识--碎片25的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片47

    1:解决ios静态库中的类别(category)在工程中不能使用 解决方法为:找到 target 的图标,更改其 Other Linker Flags 为: -all_load 或 -force_lo ...

  5. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  6. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  7. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  8. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  9. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

随机推荐

  1. iOS开发之多表视图滑动切换示例(仿"头条"客户端)---优化篇

    前几天发布了一篇iOS开发之多表视图滑动切换示例(仿"头条"客户端)的博客,之所以写这篇博客,是因为一位iOS初学者提了一个问题,简单的写了个demo做了个示范,让其在基础上做扩展 ...

  2. codefordream 关于js中级训练

    中级训练接着就紧锣密鼓的开始了. 首先是关于变量,变量的作用是给一个数据值标注名称. 注:JavaScript中变量名,函数名,参数名的命名规范:至少由字母,下划线,美元符号,数字其中的一种组成,但不 ...

  3. 【记录】ASP.NET MVC View 移动版浏览的奇怪问题

    ASP.NET MVC View 中的一段代码: <span id="span_Id">@Model.ID</span> 没什么问题吧,浏览器浏览正常,查看 ...

  4. Cocos2d-Lua (练手) 微信打飞机

    学习下lua,目前入门级,使用版本为 v3.3 Final For Win,空闲时间不足,只能断断续续写点东西.   一.子弹效果          子弹只做了一种,扇形发射,可以增加扇形大小,子弹的 ...

  5. java多线程--几个多线程面试题小结

    自学了一段时间的多线程知识,尝试了做了几个编程题,发现想象中很简单的功能,自己真写起来要花费远超自己想象的功夫,知识点易学,不易用啊. 面试题1:编写程序实现,子线程循环10次,接着主线程循环20次, ...

  6. C#运用ThoughtWorks生成二维码

    在现在的项目中,较多的使用到二维码,前面介绍过一篇使用Gma生成二维码的操作,现在介绍一个第三方组件,主要介绍生成二维码,二维码的解析,以及对二维码的相关信息的选择,现在介绍ThoughtWorks用 ...

  7. 有了jsRender,妈妈再也不用担心我用jq拼接DOM拼接的一团糟了、页面整齐了、其他伙伴读代码也不那么费劲了

    写在前面 说来也很巧, 下午再做一个页面,再普通不过的分页列表,我还是像往常一样,基于MVC环境下,我正常用PagedList.MVC AJAX做无刷新分页,这时候问题就来了,列表数据中有个轮播图用到 ...

  8. Java中的反射和注解

    前言 在Java中,反射机制和注解机制一直是一个很重要的概念,那么他们其中的原理是怎么样呢,我们不仅仅需要会使用,更要知其然而之所以然. 目录 反射机制 反射如何使用 注解定义 注解机制原理 注解如何 ...

  9. 记录下Sublime Text Mac版的快捷键【转】

    推荐使用最新版本的Chrome/Safari或者Firefox浏览器浏览此页,否则Mac按键可能无法正常展示 The Latest Version of Chrome/Safari or Firefo ...

  10. jQuery-1.9.1源码分析系列(六) 延时对象续——辅助函数jQuery.when

    $.when的说明 描述: 提供一种方法来执行一个或多个对象的回调函数,返回这些对象的延时(Deferred)对象. 说明(结合实例和源码): 如果你不传递任何参数,  jQuery.when()将返 ...