2014년 3월 31일 월요일

key value observing



UIViewController.m 파일 안에서

// register observer
    void *context = (__bridge void *)self;
    [self.tableView addObserver:self
                     forKeyPath:@"contentOffset"
                        options:NSKeyValueObservingOptionNew

                        context:context];




#pragma mark - KVO Methods

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context
{
// Make sure we are observing this value.
if (context != (__bridge void *)self) {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
return;
}
    
    if ((object == self.tableView) &&
        ([keyPath isEqualToString:@"contentOffset"] == YES)) {
        [self scrollViewDidScrollWithOffset:self.tableView.contentOffset.y];
    }
}



- (void)scrollViewDidScrollWithOffset:(CGFloat)scrollOffset
{
     // do something
}

2014년 3월 1일 토요일

storyboard 밖에서 storyboard 리소스 호출하기.

MyController is in storyboard.

and

some place in a separate view controller :

  
MyController *controller =
    [[UIStoryboard storyboardWithName:@"Main_iPhone"
                               bundle:NULL] instantiateViewControllerWithIdentifier:@"MyViewController"];
    
[self.navigationController pushViewController:controller animated:YES];

xib 소스에서 storyboard 에 있는 viewcontroller 생성하기



OutUIViewController.xib
OutUIViewController.m
OutUIViewController.h


InUIViewController.m  InUIViewController.h   in Main_

2014년 2월 26일 수요일

hexa 값으로 컬러값 한번에 설정


RGB hexa 값(0xfffefa)으로 RGB값 설정 예제)

    unsigned rgbValue = 0xfffefa;
    UIColor *bgColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0
                                       green:((rgbValue & 0xFF00) >> 8)/255.0
                                        blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
    [myView setBackgroundColor:bgColor];

2014년 2월 21일 금요일

Animation 2


방법 1)

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:newView
                             cache:YES];
    [containerView setHidden:NO];
    [containerView addSubview:newView];
    [UIView commitAnimations];


방법 2)
    [UIView transitionWithView: containerView duration:0.5
                       options:UIViewAnimationOptionCurveEaseInOut 
                    animations:^ {
                        [containerView addSubview:newView];
                    } completion:nil];



방법 3)
CATransition *animation = [CATransition animation];
[animation setDuration:0.2];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromRight];
    [newView.layer addAnimation:animation forKey:nil];
    [containerView addSubview:newView];

remove subview

CATransition *animation = [CATransition animation];
            [animation setDuration:0.5];
            [animation setType:kCATransitionReveal];
            [animation setSubtype:kCATransitionFromLeft];
            [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
            [[_refMenuContainerView layer] addAnimation:animation forKey:@"SlideView"]; //@"SwitchToNewView" , kCATransition ,,,,
            

            [subview removeFromSuperview];

2014년 2월 16일 일요일

UINavigationController 에서 뒤로(BACK) 두번 하기 (Pop)

popToViewController를 사용 하면 됨.



int viewControllerStackCount = self.navigationController.viewControllers.count;

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(viewControllerStackCount-3)] animated:YES];

2014년 2월 14일 금요일

Animation

1. UINavigationController에 present & dismiss animation 적용

////// presentedViewController animation

CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromTop;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    
    BoolshelfSubViewController *controller= [self.storyboard instantiateViewControllerWithIdentifier:@"BoolshelfSubViewController"];

    [self.navigationController pushViewController:controller animated:NO];
   

////// dismissViewControllerAnimated animation

CATransition* transition = [CATransition animation];
    transition.duration = 0.5;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionReveal;
    transition.subtype = kCATransitionFromBottom;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];

    [[self navigationController] popViewControllerAnimated:NO];


2.  UIView를 이용한 animation 적용

[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView setAnimationDuration:0.7];

[self.navigationController pushViewController:pageViewController animated:NO];
pageViewController = nil;
    
[UIView commitAnimations];


3. UIView Layer에 animation 적용 


CATransition *animation = [CATransition animation];
[animation setDuration:0.2];
[animation setType:kCATransitionMoveIn];
[animation setSubtype:kCATransitionFromRight];
    [menuView.layer addAnimation:animation forKey:nil];

    [_menuContainerView addSubview:menuView];