메뉴 건너뛰기

app

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

박영식2009.10.01 03:47조회 수 4465댓글 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 박영식)

댓글 달기

박영식
2010.09.09 조회 4787
박영식
2010.05.25 조회 4090
박영식
2010.01.14 조회 4969
박영식
2009.09.21 조회 4146
박영식
2008.08.18 조회 6061
박영식
2008.08.17 조회 4192
박영식
2008.07.24 조회 4621
박영식
2008.07.23 조회 7998
박영식
2008.07.22 조회 3347
박영식
2008.04.11 조회 2198
박영식
2008.01.20 조회 2038
박영식
2007.12.23 조회 3222
첨부 (2)
Calendar.zip
619.4KB / Download 84
cal.jpg
91.5KB / Download 44
위로