[iPhone] UIView FAQ

来源:互联网 发布:全国打击网络电信诈骗 编辑:程序博客网 时间:2024/05/29 02:47
1, Transform
  Just write following codes to scale (also called zoom in/out, or transform) your view:
    float scaleX = xxx, scaleY = xxx;
    CGAffineTransform transform = CGAffineTransformMakeScale(scaleX, scaleY];
    yourView.transform = transform;
 After scaled, you can set scaleX, and scaleY to scale to original size.
2, Animation
 - (void) transformYourView()
 {
      float scaleX = xxx, scaleY = xxx;
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:0.15]; //The default value is 0.2
      [UIView setAnimationDelegate:self];
      [UIView setAnimationDidStopSelector:@selector(animationFinshed:finsihed:context:)];
      CGAffineTransform transform = CGAffineTransformMakeScale(scaleX, scaleY];
      yourView.transform = transform;
      [UIView commitAnimations];
  }

- (void) animationFinshed:(NSString *) animationID finished:(NSNumber *)finished context:(void *)context
{
    //To here, animation is finshed
}

3, Handle touch tap event;
You must customize UIView, and handle event.
//UICView.h
@interface UICView : UIView
@end


//UICView.m
@implementation UICView
//Handle touches began event
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    printf("members count=%i/r/n", touches.count);
    for (UITouch *touch in touches)
    {
        printf("tap count = %i/r/n", touch.tapCount); //for dragging event, touch.tapCount is 0
    }
   
   [self touchesBegin:touches withEvent:event]; //You must invoke thisinterface, otherwise, application may can't handle event correctly.
}

@end