蓝懿 ios技术交流和心得分享12.28

- (void)viewDidLoad { [super viewDidLoad]; // 1.监听通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.accountField]; } //监听结束需要移除- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; }

#import "TutorialProjectViewController.h"@implementation TutorialProjectViewController@synthesize threadValueLabel, threadProgressView, testValueLabel, threadStartButton;// ------ Tutorial code starts here ------- (IBAction) startThreaonPressed:(UIButton *)sender {        threadStartButton.hidden = YES;    threadValueLabel.text = @"0";    threadProgressView.progress = 0.0;    [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];    }- (void)startTheBackgroundJob {      //注册一个监听者    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Update) name:@"UpdateTableView" object:nil];      NSLog(@"1111111111");    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    // wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time    [NSThread sleepForTimeInterval:3];    [self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];    [pool release];    }- (void)makeMyProgressBarMoving {    xx++;//  NSLog(@"22222222 %i",xx);    float actual = [threadProgressView progress];    threadValueLabel.text = [NSString stringWithFormat:@"%.2f", actual];    if (actual < 1) {        threadProgressView.progress = actual + 0.01;        [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];     }    if (xx==5||xx==15) {                //发出一个消息。此前注册的监听者可以发现这个消息,并且出发相应的方法        [[NSNotificationCenter defaultCenter] postNotificationName:@"UpdateTableView" object:nil];            NSLog(@"xxxxxxxxxxxxxx==3");    }    if (xx==10) {        //取消监听。        [[NSNotificationCenter defaultCenter] removeObserver:self name:@"UpdateTableView" object:nil];    }    else threadStartButton.hidden = NO;    }//受到监听的消息时,调用这个函数-(void)Update{    NSLog(@"----------sdafs");}- (IBAction) testValueSliderChanged:(UISlider *)sender {        testValueLabel.text = [NSString stringWithFormat:@"%.2f", sender.value];    }// ------ Tutorial code ends here ------- (void)didReceiveMemoryWarning {    // Releases the view if it doesn't have a superview.    [super didReceiveMemoryWarning];        // Release any cached data, images, etc that aren't in use.}- (void)viewDidUnload {    // Release any retained subviews of the main view.    // e.g. self.myOutlet = nil;}// This function is for button which takes you to the xprogress.com website- (IBAction) runXprogressComButton: (id) sender {    NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.xprogress.com/" ];    [[UIApplication sharedApplication] openURL:url];}- (void)dealloc {        // ------ Tutorial code starts here ------        [threadValueLabel release];    [threadProgressView release];    [threadStartButton release];        [testValueLabel release];        // ------ Tutorial code ends here ------        [super dealloc];}@end​

 

  • UITapGestureRecognizer
  • UIPinchGestureRecognizer
  • UIRotationGestureRecognizer
  • UISwipeGestureRecognizer
  • UIPanGestureRecognizer
  • UILongPressGestureRecognizer

从命名上不难了解這些类別所对应代表的手势,分別是 Tap(点一下)、Pinch(二指往內或往外拨动)、Rotation(旋转)、Swipe(滑动,快速移动)、Pan (拖移,慢速移动)以及 LongPress(长按)。這些手势別在使用上也很简单,只要在使用前定义并添加到对应的视图上即可。

// 定义一个 recognizer, 并加到需要偵測该手势的 UIView 元件上

-

 (void)viewDidLoad {

    UISwipeGestureRecognizer

*

 recognizer;

    // handleSwipeFrom 是偵測到手势,所要呼叫的方法

    recognizer

 = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSwipeFrom)];

    // 不同的 Recognizer 有不同的实体变数

    // 例如 SwipeGesture 可以指定方向

    // 而 TapGesture 則可以指定次數

    recognizer

.

direction

 = UISwipeGestureRecognizerDirectionUp

    [

self

.

view

 addGestureRecognizer:recognizer];

    [

recognizer

 release];

 }

 

 -

 (void)handleSwipeFrom:(UISwipeGestureRecognizer*)recognizer {

    // 触发手勢事件后,在这里作些事情

    // 底下是刪除手势的方法

    [

self

.

view

 removeGestureRecognizer:recognizer];

 }

问题來了。有些手势其实是互相关联的,例如 Tap 与 LongPress、Swipe与 Pan,或是 Tap 一次与Tap 兩次。当一個 UIView 同时添加兩个相关联的手势时,到底我这一下手指头按的要算是 Tap 还是 LongPress?如果照預设作法来看,只要「先滿足条件」的就会跳出并呼叫对应方法,举例来说,如果同时注册了 Pan 和 Swipe,只要手指头一移动就会触发 Pan 然后跳出,因而永远都不會发生 Swipe;单点与双点的情形也是一样,永远都只会触发单点,不會有双点。

那么这个问题有解吗?答案是肯定的,

UIGestureRecognizer 

有个方法叫做

requireGestureRecognizerToFail

,他可以指定某一个 recognizer,即便自己已经滿足條件了,也不會立刻触发,会等到该指定的 recognizer 确定失败之后才触发。以同时支持单点与双点的手势为例,代码如下:

-

 (void)viewDidLoad {

    // 单击的 Recognizer

    UITapGestureRecognizer

*

 singleRecognizer;

    singleRecognizer

 = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleSingleTapFrom)];

    singleTapRecognizer

.

numberOfTapsRequired

 = 1; // 单击

    [

self

.

view

 addGestureRecognizer:singleRecognizer];

    

    // 双击的 Recognizer

    UITapGestureRecognizer

*

 double;

    doubleRecognizer

 = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(handleDoubleTapFrom)];

    doubleTapRecognizer

.

numberOfTapsRequired

 = 2; // 双击

    [

self

.

view

 addGestureRecognizer:doubleRecognizer];

    

    // 关键在这一行,如果双击确定偵測失败才會触发单击

    [

singleRecognizer

 requireGestureRecognizerToFail:doubleRecognizer];

    [

singleRecognizer

 release];

    [

doubleRecognizer

 release];

}

学习ios  重要还是要理清楚思路  在做或者看老师代码的时候 自己多想想为什么  不要自己看着就抄       另外还是要推荐一下 蓝懿IOS这个培训机构  和刘国斌老师刘国斌老师还是很有名气的,听朋友说刘老师成立了蓝懿iOS,,老师讲课方式很独特,能够尽量让每个人都能弄明白,有的比较难懂的地方,如果有的地方还是不懂得话,老师会换个其它方法再讲解,这对于我们这些学习iOS的同学是非常好的,多种方式的讲解会理解得更全面,这个必须得给个赞,嘻嘻,还有就是这里的学习环境很好,很安静,可以很安心的学习,安静的环境是学习的基础,小班讲课,每个班20几个学生,学习氛围非常好,每天都学到9点多才离开教室,练习的时间很充裕,而且如果在练习的过程中有什么困难,随时可以向老师求助,不像其它机构,通过视频教学,有的甚至学完之后都看不到讲师本人,问点问题都不方便,这就是蓝懿与其它机构的区别,相信在刘国斌老师的细心指导下,每个蓝懿学员都能找到满意的工作,加油!

                                                                  写博客第七十九天;

                                                                              QQ:565803433


  1.     [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillShow:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardShow:)
                                                     name:UIKeyboardDidShowNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillHide:)
                                                     name:UIKeyboardWillHideNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardHide:)
                                                     name:UIKeyboardDidHideNotification
                                                   object:nil];
    
    复制代码
  2. 在键盘将要出现和隐藏的回调中,加入动画。
    复制代码
    - (void)keyboardWillShow:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
        
        CGRect rect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGFloat y = rect.origin.y;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.25];
        NSArray *subviews = [self subviews];
        for (UIView *sub in subviews) {
            
            CGFloat maxY = CGRectGetMaxY(sub.frame);
            if (maxY > y - 2) {
                sub.center = CGPointMake(CGRectGetWidth(self.frame)/2.0, sub.center.y - maxY + y - 2);
            }
        }
        [UIView commitAnimations];
    }
    
    - (void)keyboardShow:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
    }
    
    - (void)keyboardWillHide:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.25];
        NSArray *subviews = [self subviews];
        for (UIView *sub in subviews) {
            if (sub.center.y < CGRectGetHeight(self.frame)/2.0) {
                sub.center = CGPointMake(CGRectGetWidth(self.frame)/2.0, CGRectGetHeight(self.frame)/2.0);
            }
        }
        [UIView commitAnimations];
    }
    
    - (void)keyboardHide:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
    }
    
    复制代码
  1.     [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillShow:)
                                                     name:UIKeyboardWillShowNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardShow:)
                                                     name:UIKeyboardDidShowNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardWillHide:)
                                                     name:UIKeyboardWillHideNotification
                                                   object:nil];
        
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(keyboardHide:)
                                                     name:UIKeyboardDidHideNotification
                                                   object:nil];
    
    复制代码
  2. 在键盘将要出现和隐藏的回调中,加入动画。
    复制代码
    - (void)keyboardWillShow:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
        
        CGRect rect = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        CGFloat y = rect.origin.y;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.25];
        NSArray *subviews = [self subviews];
        for (UIView *sub in subviews) {
            
            CGFloat maxY = CGRectGetMaxY(sub.frame);
            if (maxY > y - 2) {
                sub.center = CGPointMake(CGRectGetWidth(self.frame)/2.0, sub.center.y - maxY + y - 2);
            }
        }
        [UIView commitAnimations];
    }
    
    - (void)keyboardShow:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
    }
    
    - (void)keyboardWillHide:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.25];
        NSArray *subviews = [self subviews];
        for (UIView *sub in subviews) {
            if (sub.center.y < CGRectGetHeight(self.frame)/2.0) {
                sub.center = CGPointMake(CGRectGetWidth(self.frame)/2.0, CGRectGetHeight(self.frame)/2.0);
            }
        }
        [UIView commitAnimations];
    }
    
    - (void)keyboardHide:(NSNotification *)notif {
        if (self.hidden == YES) {
            return;
        }
    }
    
    复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您的问题是关于动态时间规整算法的声音匹配问题,我会尽力回答。根据您的要求,我会保密您的问题,以下是对您的问题的回答: 动态时间规整算法(Dynamic Time Warping,DTW)可以用于语音序列的比对,它可以解决语音序列的不同长度及速度变化的问题。下面是对您提出的问题的回答: 首先,我们需要计算出语音序列a和b之间的距离,然后根据这些距离结果,构建出一个匹配矩阵,最后通过匹配矩阵来找到最好的语音匹配路径和距离。 计算距离:对于两个特征向量ai和bj,我们可以用欧几里得距离或曼哈顿距离来计算它们之间的距离,然后用这些距离的集合作为DTW的距离度量。 然后,我们可以通过动态规划的方式计算匹配矩阵。匹配矩阵的第(i,j)个元素表示从a序列的第i个位置到b序列的第j个位置的所有可能配对方案中,最好的一种方案的距离。匹配矩阵中的第一行和第一列为0,因为我们认为第一个位置到任何一个位置的距离都是0。 最后,我们可以从匹配矩阵的右下角开始回溯,利用动态规划的原则来找到最佳的语音匹配路径和距离。 匹配矩阵: 0 inf inf inf inf inf inf inf inf inf inf 0 2.83 5.66 7.81 10.49 10.92 11.66 12.37 14.04 16.62 19.45 0 3.61 5 6.16 7.81 8.06 9.37 12.06 14.32 16.4 17.92 0 4.24 4.9 5.92 6.71 7.07 8.48 11.49 14.21 15.68 17.62 0 6.08 6.18 7.81 6.52 7.21 8.71 9 11.57 13.6 13.6 0 13.18 12.56 12.69 11.18 9.9 9.49 9.43 10.75 12.44 11.66 0 14.87 16.49 16.15 12.23 11.06 10.24 10.05 12.28 11.95 12.37 0 18.83 19.85 20.35 15.53 12.2 11.95 12.24 13.54 15.28 17.43 0 20.96 24.75 25.27 20.09 16.64 15.72 17.11 17.26 18.97 20.16 0 21.84 26.04 28.56 24.24 22 20.99 22.25 22.11 20.92 21.29 最佳匹配距离:21.29 最佳匹配路径:[(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 5), (7, 6), (8, 7), (9, 8), (10, 9)]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值