메뉴 건너뛰기

app

[iphone] Calendar - 터치 이벤트 추가

박영식2009.10.01 03:47조회 수 4275댓글 0

  • 2
    • 글자 크기

//

//  SwitchViewController.m

//  Calendar

//

//  Created by student on 09. 09. 29.

//  Copyright 2009 __MyCompanyName__. All rights reserved.

//


#import "SwitchViewController.h"

#import "BlueViewController.h"

#import "YellowViewController.h"



@implementation SwitchViewController


int dayInt;

int monthInt;

int yearInt;


NSString *dayString = nil;

NSString *monthString = nil;

NSString *yearString = nil;


@synthesize yellowViewController;

@synthesize blueViewController;

@synthesize dayLabel;

@synthesize monthLabel;

@synthesize yearLabel;

@synthesize gestureStartPoint;

/*

 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

        // Custom initialization

    }

    return self;

}

*/


/*

// Implement loadView to create a view hierarchy programmatically, without using a nib.

- (void)loadView {

}

*/



#pragma mark -

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    

    UITouch *touch = [touches anyObject];

    gestureStartPoint = [touch locationInView:self.view];

    

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    

    UITouch *touch = [touches anyObject];

    CGPoint currentPosition = [touch locationInView:self.view];

    

    CGFloat deltaX = gestureStartPoint.x - currentPosition.x;

    CGFloat deltaY = gestureStartPoint.y - currentPosition.y;

    

    if (fabsf(deltaX) == kMinimumGestureLength && fabsf(deltaY) <= kMaximumVariance) {

if(deltaX>0){//premonth

if(monthInt == 1){

dayInt = 31;

monthInt = 12;

yearInt = yearInt - 1;

}else{

if(monthInt == 3 && dayInt > 28){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

}else if(dayInt == 31){

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

dayInt=30;

}

}

monthInt=monthInt-1;

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

[UIView beginAnimations:@"View Flip" context:nil];

[UIView setAnimationDuration:1.25];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionFlipFromRight

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}else{//postmonth

if(monthInt >= 12){

monthInt = 1;

yearInt = yearInt + 1;

}else{

if(monthInt == 1 && dayInt > 28){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

}else if(dayInt == 31){

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  8 ||monthInt ==  10){

dayInt=30;

}

}

monthInt=monthInt+1;

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

[UIView beginAnimations:@"View Flip" context:nil];

[UIView setAnimationDuration:1.25];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionFlipFromLeft

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}

    }

    else if (fabsf(deltaY) == kMinimumGestureLength &&

             fabsf(deltaX) <= kMaximumVariance){

if(deltaY>0){//postday

if(monthInt == 1 ||monthInt ==  3 ||monthInt ==  5 ||monthInt ==  7 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

if(dayInt > 30){

dayInt=1;

if(monthInt >= 12){

monthInt = 1;

yearInt = yearInt + 1;

}else{

monthInt=monthInt+1;

}

}else{

dayInt=dayInt+1;

}

}else if(monthInt == 2){

if(yearInt%400==0){

if(yearInt%100==0){

if(dayInt > 28){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}else{

if(dayInt > 27){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}

}else{

if(yearInt%4==0){

if(dayInt > 28){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}else{

if(dayInt > 27){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}

}

}else{

if(dayInt > 29){

dayInt=1;

if(monthInt >= 12){

monthInt = 1;

}else{

monthInt=monthInt+1;

}

}else{

dayInt=dayInt+1;

}

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

[UIView beginAnimations:@"View Flip" context:nil];

[UIView setAnimationDuration:1.25];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionCurlUp

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}else{//preday

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  7 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

if(dayInt == 1){

dayInt=30;

if(monthInt == 1){

monthInt = 12;

yearInt = yearInt - 1;

}else{

monthInt=monthInt-1;

}

}else{

dayInt=dayInt-1;

}

}else if(monthInt == 3){

if(dayInt == 1){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

monthInt=monthInt-1;

}else{

dayInt=dayInt-1;

}

}else{

if(dayInt == 1){

dayInt=31;

if(monthInt == 1){

monthInt = 12;

}else{

monthInt=monthInt-1;

}

}else{

dayInt=dayInt-1;

}

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

[UIView beginAnimations:@"View Flip" context:nil];

[UIView setAnimationDuration:1.25];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionCurlDown

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}

    }

    

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

self.blueViewController = [ [ BlueViewController alloc ]

  initWithNibName:@"BlueView" bundle:nil ];

[ self.view insertSubview:self.blueViewController.view atIndex:0 ];

[ self.blueViewController release ];

NSDate *today = [ [ NSDate alloc ] init ];

NSDateFormatter *dateFormatter = [ [ NSDateFormatter alloc ] init ];

[ dateFormatter setDateFormat:@"MM" ];

monthInt =[ [ dateFormatter stringFromDate:today ] intValue ];

[ dateFormatter setDateFormat:@"dd" ];

dayInt =[ [ dateFormatter stringFromDate:today ] intValue ];

[ dateFormatter setDateFormat:@"y" ];

yearInt = [ [ dateFormatter stringFromDate:today ] intValue ];

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

//    [super viewDidLoad];

}

- ( IBAction ) postmonth:( id ) sender

{

if(monthInt >= 12){

monthInt = 1;

yearInt = yearInt + 1;

}else{

if(monthInt == 1 && dayInt > 28){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

}else if(dayInt == 31){

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  8 ||monthInt ==  10){

dayInt=30;

}

}

monthInt=monthInt+1;

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

    [UIView beginAnimations:@"View Flip" context:nil];

    [UIView setAnimationDuration:1.25];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionFlipFromLeft

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}


- ( IBAction ) postday:( id ) sender

{

if(monthInt == 1 ||monthInt ==  3 ||monthInt ==  5 ||monthInt ==  7 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

if(dayInt > 30){

dayInt=1;

if(monthInt >= 12){

monthInt = 1;

yearInt = yearInt + 1;

}else{

monthInt=monthInt+1;

}

}else{

dayInt=dayInt+1;

}

}else if(monthInt == 2){

if(yearInt%400==0){

if(yearInt%100==0){

if(dayInt > 28){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}else{

if(dayInt > 27){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}

}else{

if(yearInt%4==0){

if(dayInt > 28){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}else{

if(dayInt > 27){

dayInt=1;

monthInt=monthInt+1;

}else{

dayInt=dayInt+1;

}

}

}

}else{

if(dayInt > 29){

dayInt=1;

if(monthInt >= 12){

monthInt = 1;

}else{

monthInt=monthInt+1;

}

}else{

dayInt=dayInt+1;

}

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

    [UIView beginAnimations:@"View Flip" context:nil];

    [UIView setAnimationDuration:1.25];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionCurlUp

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}


- ( IBAction ) premonth:( id ) sender

{

if(monthInt == 1){

monthInt = 12;

yearInt = yearInt - 1;

}else{

if(monthInt == 3 && dayInt > 28){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

}else if(dayInt == 31){

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

dayInt=30;

}

}

monthInt=monthInt-1;

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

    [UIView beginAnimations:@"View Flip" context:nil];

    [UIView setAnimationDuration:1.25];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionFlipFromRight

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}


- ( IBAction ) preday:( id ) sender

{

if(monthInt == 3 ||monthInt ==  5 ||monthInt ==  7 ||monthInt ==  8 ||monthInt ==  10 ||monthInt ==  12){

if(dayInt == 1){

dayInt=30;

if(monthInt == 1){

monthInt = 12;

yearInt = yearInt - 1;

}else{

monthInt=monthInt-1;

}

}else{

dayInt=dayInt-1;

}

}else if(monthInt == 3){

if(dayInt == 1){

if(yearInt%400==0){

if(yearInt%100==0){

dayInt=29;

}else{

dayInt=28;

}

}else{

if(yearInt%4==0){

dayInt=29;

}else{

dayInt=28;

}

}

monthInt=monthInt-1;

}else{

dayInt=dayInt-1;

}

}else{

if(dayInt == 1){

dayInt=31;

if(monthInt == 1){

monthInt = 12;

}else{

monthInt=monthInt-1;

}

}else{

dayInt=dayInt-1;

}

}

dayString = [ [ NSString alloc ] initWithFormat:

@" %d", dayInt ];

monthString = [ [ NSString alloc ] initWithFormat:

  @" %d", monthInt ];

yearString = [ [ NSString alloc ] initWithFormat:

  @" %d", yearInt ];

dayLabel.text = dayString;

monthLabel.text = monthString;

yearLabel.text = yearString;

    [UIView beginAnimations:@"View Flip" context:nil];

    [UIView setAnimationDuration:1.25];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:

UIViewAnimationTransitionCurlDown

  forView:self.view cache:YES];

[ UIView commitAnimations ];

}


/*

// Override to allow orientations other than the default portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

*/


- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

    [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}


- (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}



- (void)dealloc {

    [super dealloc];

}



@end


박영식 (비회원)
  • 2
    • 글자 크기
[xcode] 한글 사용하기 NSUTF8StringEncoding (by 박영식) [xcode] Let me introduce (by 박영식)

댓글 달기

이전 1 ... 3 4 5 6 7 8 9 10 11 12... 14다음
첨부 (2)
Calendar.zip
619.4KB / Download 66
cal.jpg
91.5KB / Download 29
위로