search

Home  >  Q&A  >  body text

objective-c - OC编译器是如何处理执行某段代码的?


 CGRect frame=  self.bg.frame;
    
    [UIView   beginAnimations:nil context:nil];
    [UIView  setAnimationDuration:2];
    
    long tag=sender.tag;
    switch (tag) {
        case 10:
            frame.origin.y-=30;
            break;
        case 20:
            frame.origin.y+=30;
            break;
        default:
            break;
    }
    
    self.bg.frame=frame;
    [UIView commitAnimations];

中间这部分代码将被执行动画。
我有一个比较奇葩的问题,就是这部分动画代码,编译器是如何获得的呢?

我的心里是这么想的,当然是伪代码表述:就是用String去截取,把这段代码截取出来去执行。。

求教。。

还有顺便一个问题,我一起问了吧。
self.bg.frame=frame;这样位置就变了。。那么OC或者说IOS肯定是不断监听这个属性的变化的。。那么IOS中事件模型是怎样的呢?

ringa_leeringa_lee2771 days ago437

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-04-24 09:16:03

    There is another way, which is that it must be executed sequentially. . . Only when commitAnimations is reached is the actual submission.

    - (IBAction)move:(UIButton *)sender {
      CGRect frame=  self.bg.frame;
        
        [UIView   beginAnimations:nil context:nil];
        NSLog(@"执行到了这里beginAnimations");
        [UIView  setAnimationDuration:2];
        NSLog(@"执行到了这里setAnimationDuration");
        long tag=sender.tag;
        switch (tag) {
            case 10:
                frame.origin.y-=30;
                break;
            case 20:
                frame.origin.y+=30;
                break;
            default:
                break;
        }
        
        self.bg.frame=frame;
           NSLog(@"执行到了这里2");
        [UIView commitAnimations];
           NSLog(@"commitAnimations");
      
    }

    The result of the operation:
    2015-08-28 1520.020 02 Calculator [1403:73936] The execution reaches here beginAnimations
    2015-08-28 1520.021 02 Calculator [1403:73936] Execution reaches here setAnimationDuration
    2015-08-28 1520.022 02Calculator[1403:73936] Execution reaches here 2
    2015-08-28 1520.022 02Calculator[1403:73936] commitAnimations

    That is to say, the code must be executed sequentially. . There is no mention of extracting the code and executing it. self.bg.frame=frame; When executing, there must be something similar to obtaining animation status. .

    reply
    0
  • 迷茫

    迷茫2017-04-24 09:16:03

    google: render tree, render tree

    reply
    0
  • Cancelreply