2014년 9월 23일 화요일

시, 분, 초 계산 방법


   CFTimeInterval _ticks;




    _ticks += 0.1;
    double seconds = fmod(_ticks, 60.0);
    double minutes = fmod(trunc(_ticks / 60.0), 60.0);
    double hours = trunc(_ticks / 3600.0);
    self.timerLabel.text = [NSString stringWithFormat:@"%02.0f:%02.0f:%04.1f", hours, minutes, seconds];
    

    NSLog(@"tick = %f text = %@", _ticks, self.timerLabel.text);





2014-09-24 02:59:49.241 TabbedBanner[961:60b] tick = 0.100000 text = 00:00:00.1
2014-09-24 02:59:49.341 TabbedBanner[961:60b] tick = 0.200000 text = 00:00:00.2
2014-09-24 02:59:49.441 TabbedBanner[961:60b] tick = 0.300000 text = 00:00:00.3
...
2014-09-24 02:59:53.141 TabbedBanner[961:60b] tick = 4.000000 text = 00:00:04.0
2014-09-24 02:59:53.241 TabbedBanner[961:60b] tick = 4.100000 text = 00:00:04.1
2014-09-24 02:59:53.341 TabbedBanner[961:60b] tick = 4.200000 text = 00:00:04.2
2014-09-24 02:59:53.441 TabbedBanner[961:60b] tick = 4.300000 text = 00:00:04.3
...
2014-09-24 03:03:35.186 TabbedBanner[961:60b] tick = 224.900000 text = 00:03:44.9
2014-09-24 03:03:35.286 TabbedBanner[961:60b] tick = 225.000000 text = 00:03:45.0
2014-09-24 03:03:35.386 TabbedBanner[961:60b] tick = 225.100000 text = 00:03:45.1
2014-09-24 03:03:35.486 TabbedBanner[961:60b] tick = 225.200000 text = 00:03:45.2
2014-09-24 03:03:35.586 TabbedBanner[961:60b] tick = 225.300000 text = 00:03:45.3
2014-09-24 03:03:35.686 TabbedBanner[961:60b] tick = 225.400000 text = 00:03:45.4

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) {

    }];

2014년 7월 18일 금요일

UICollectionView 에서 orientation이변경할때 landscape, portrait에 따라서 cell 사이즈 자역스럽게 변경하기

1.  orientation이 바뀌었을때 새로운 layout을 변경 적용.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
...
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumInteritemSpacing = 0.f;
    layout.minimumLineSpacing = 0.f;
    layout.sectionInset = UIEdgeInsetsZero;
    [self.collectionView setCollectionViewLayout:layout animated:YES];
    [_collectionView scrollToItemAtIndexPath:currentIndexPath             atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}

2. UICollectionView delegate 에서 함수 사이즈 return

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation])) {
        return CGSizeMake(320.f, 180.f);
    }
    return CGSizeMake(568.f, 320.f);
}

2014년 7월 2일 수요일

UISlider 커스텀

이미지의 사이즈에 맞게 slider의 높이 및 thumb 이미지 교체, 및 slider 의 track을 이미지로 대체.



UIImage *minImage = [[UIImage imageNamed:@"slider_minimum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    UIImage *maxImage = [[UIImage imageNamed:@"slider_maximum.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
    UIImage *thumbImage = [UIImage imageNamed:@"sliderhandle.png"];
    
    [[UISlider appearance] setMaximumTrackImage:maxImage forState:UIControlStateNormal];
    [[UISlider appearance] setMinimumTrackImage:minImage forState:UIControlStateNormal];
    [[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];



2014년 6월 2일 월요일

Button array에 있는 객체의 속성을 한번에 바꾸는 방법.


예제 1)
[_arrowButtons setValue:@NO forKeyPath:@"userInteractionEnabled"];


예제2)
[self.starImageViews setValue:@NO forKey:@"highlighted"];