2014년 8월 13일 수요일

UITextField 의 text 가 영인지 체크하는 방법




- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSRange textFieldRange = NSMakeRange(0, [textField.text length]);
    if (NSEqualRanges(range, textFieldRange) && [string length] == 0) {
        [_keywordClearButton setHidden:YES];
    } else
        [_keywordClearButton setHidden:NO];
    
    return YES;

}

2014년 8월 5일 화요일

rotate 360 degree


1)

CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
    fullRotation.fromValue = [NSNumber numberWithFloat:0];
    fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
    fullRotation.duration = .3f;
    fullRotation.repeatCount = 1;

    [self.layer addAnimation:fullRotation forKey:@"360"];

2)

if(rotationCount == 3) {
        [UIView animateWithDuration:.4f delay:0.f usingSpringWithDamping:.5f initialSpringVelocity:0.f options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        } completion:^(BOOL finished) {
            if (finished) {
                return;
            }
        }];
    }
    else {
        
        [UIView animateWithDuration:.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        } completion:^(BOOL finished) {
            [self rotateAnimation];
        }];
        
    }
    
    rotationCount++;


3)

[UIView animateKeyframesWithDuration:.8f delay:0.0 options:UIViewKeyframeAnimationOptionCalculationModeLinear|UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{
        
        // push the from- view to the back
        [UIView addKeyframeWithRelativeStartTime:0.0f relativeDuration:0.4f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        }];
        [UIView addKeyframeWithRelativeStartTime:0.2f relativeDuration:0.4f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        }];
        
        // slide the to- view upwards. In his original implementation Tope used a 'spring' animation, however
        // this does not work with keyframes, so we siulate it by overshooting the final location in
        // the first keyframe
        [UIView addKeyframeWithRelativeStartTime:0.6f relativeDuration:0.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        }];
        [UIView addKeyframeWithRelativeStartTime:0.8f relativeDuration:0.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_2)];
        }];
        /*
        [UIView addKeyframeWithRelativeStartTime:1.f relativeDuration:0.4f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, -(M_PI_2))];
        }];
        
        [UIView addKeyframeWithRelativeStartTime:.9f relativeDuration:0.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, M_PI_4)];
        }];
        [UIView addKeyframeWithRelativeStartTime:1.4f relativeDuration:0.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformRotate(_thumbnailImage.transform, -(M_PI_4))];
        }];
        [UIView addKeyframeWithRelativeStartTime:1.8f relativeDuration:0.2f animations:^{
            [_thumbnailImage setTransform:CGAffineTransformIdentity];
        }];*/
        
        
    } completion:^(BOOL finished) {
    }];

flip 360 degree


1) horizontally flip


_bodyView.transform = CGAffineTransformScale(_bodyView.transform, 1, -1);
    
    [UIView animateWithDuration:.5f delay:0 usingSpringWithDamping:.3f initialSpringVelocity:70.f options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        
        _bodyView.transform = CGAffineTransformScale(_bodyView.transform, 1, -1);
        
    } completion:^(BOOL finished) {

    }];