objective c - When does setter method get called from UIView subclass -


i taking free stanford course on itunesu(193p) , created setting class subclass of uiview , created public property called scale. idea when pinch, scale of view changed accordingly confused when setter of property scale gets called. here relevant code below:

@interface faceview : uiview  @property (nonatomic) cgfloat scale; //anyone wants publicly can set scale  -(void)pinch:(uipinchgesturerecognizer *)gesture;  @end 
@synthesize scale = _scale;  #define default_scale 0.90  -(cgfloat)scale{     if(!_scale){         return default_scale;     }else {         return _scale;     } }  -(void)setscale:(cgfloat)scale{     nslog(@"setting scale");     if(scale != _scale){         _scale = scale;         [self setneedsdisplay];     } }  -(void)pinch:(uipinchgesturerecognizer *)gesture{      if ( (gesture.state == uigesturerecognizerstatechanged) || (gesture.state == uigesturerecognizerstateended)){          self.scale *= gesture.scale;         gesture.scale = 1;     } } 

when in "pinch mode" setscale method continues called pinching nslog statement prints out until stop pinch. when or how setscale method continued called when there isn't code programmatically calling it? perhaps missed along way here.

@cspam, remember set gesture recognizer 2 steps:
1) adding gesture recognizer uiview - kind of confused me in lecture eventhough saying add gesture recognizer uiview, means add gesture recognizer uiview, in uiviewcontroller. code missing have add in uiviewcontroller subclass in case (the faceviewcontroller - name might different) , keep calling pinch method in faceview above:

 uipinchgesturerecognizer *pinchgesture=[[uipinchgesturerecognizer alloc]initwithtarget:self.faceview action:@selector(pinch)];   [self.faceview addgesturerecognizer:pinchgesture]; 

you add code in uiviewcontroller (subclass) in setter method of uiview [in other words, create , connect iboutlet property in uiviewcontroller uiview in storyboard] , override setter method include code above.

2) second part have in code. pinch method called everytime controller senses pinch gesture.

hope helps.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -