2011년 5월 26일 목요일

iphone media 화일 재생

//
//  SampleDay9_2ViewController.h
//  SampleDay9-2
//
//  Created by bit on 11. 5. 26..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import
#import

@interface SampleDay9_2ViewController : UIViewController {

MPMoviePlayerController* player;
}

-(IBAction)onStart:(id)sender;
-(void)movieFinishCallback:(NSNotification*)aNotification;

@end


//
//  SampleDay9_2ViewController.m
//  SampleDay9-2
//
//  Created by bit on 11. 5. 26..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//



#import "SampleDay9_2ViewController.h"

// include 추가한다... 
// SDK     Media Framework 추가 한다
#import

@implementation SampleDay9_2ViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];

}



/*
// 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];
}

-(void)movieFinishCallback:(NSNotification*)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
}
-(IBAction)onStart:(id)sender
{
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:moviePath];
// 서버에 리모트로 접근시 
// NSURL *url = [NSURL URLWithString:moviePath];
MPMoviePlayerViewController *mpView = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
//self.player = mpView.moviePlayer;
[self presentModalViewController:mpView animated:YES];
}
@end

iphone imagePicker 사용하여 이미지 버튼만들기

//
//  SampleDay9_1ViewController.h
//  SampleDay9-1
//
//  Created by bit on 11. 5. 26..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import

@interface SampleDay9_1ViewController : UIViewController {

IBOutlet UIButton *pictureButton;
}

@property (nonatomic, retain ) IBOutlet UIButton *pictureButton;

-(IBAction) onPhotoClicked:(id)sender ;

-(void)showImagePickerWithSourceType:(UIImagePickerControllerSourceType)sourceType ;
- (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info;



@end




//
//  SampleDay9_1ViewController.m
//  SampleDay9-1
//
//  Created by bit on 11. 5. 26..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay9_1ViewController.h"

@implementation SampleDay9_1ViewController

@synthesize pictureButton;



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/


/*
// 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 {
[pictureButton release];
[super dealloc];
}


-(IBAction) onPhotoClicked:(id)sender 
{
UIActionSheet *asheet;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ) {
asheet = [[UIActionSheet alloc] initWithTitle:@"Select Data Source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Photo Album", @"Camera", nil ];
}
else {
asheet = [[UIActionSheet alloc] initWithTitle:@"Select Data Source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Photo Album", nil ];
}
[asheet showInView:self.view];
[asheet release];
}


#pragma mark UICationSheet Delegate

-(void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if( buttonIndex == [actionSheet cancelButtonIndex]) return;
if(buttonIndex == 0 ) {
[self showImagePickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
else if ( buttonIndex == 1 ) {
[self showImagePickerWithSourceType:UIImagePickerControllerSourceTypeCamera];
}
}


#pragma mark Image Picker Loading

-(void)showImagePickerWithSourceType:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease ];
picker.sourceType = sourceType;
picker.allowsEditing = (sourceType == UIImagePickerControllerSourceTypeCamera );
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
}

#pragma mark UIImagePickerController delegate

- (void) imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {

UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[pictureButton setImage:image forState:UIControlStateNormal];
[picker dismissModalViewControllerAnimated:YES];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}

@end

iphone Quartz Animation

1.Quartz SDK  를 추가한다.




//
//  SampleDay9ViewController.m
//  SampleDay9
//
//  Created by bit on 11. 5. 26..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay9ViewController.h"

// 아래 소스를 넣어 주어야 한다..  자동완성 기능을 사용하기 위해서라도.. 

#import

@implementation SampleDay9ViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
UIButton *button = (UIButton *)[self.view viewWithTag:TAG_BUTTON];
[button addTarget:self action:@selector(animated:) forControlEvents:UIControlEventTouchUpInside];
}



/*
// 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];
}

-(IBAction)animated:(id)sender {
NSLog(@"Clicked Button!!!");
UIView *theView = [self.view viewWithTag:TAG_VIEW];
// transaction 기능은
// - 없어도 돌아 간다
// - randering 위해서... 
// - 추가 설정이 가능하다... 
// - 기본적인 설정을 받아서 사용할수 있다.. 
// Key-Value 코딩 설명 
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:2.0f] forKey:kCATransactionAnimationDuration];
CABasicAnimation *shrinkAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrinkAnimation.delegate = self;
shrinkAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
shrinkAnimation.toValue = [NSNumber numberWithFloat:0.0f];
[theView.layer addAnimation:shrinkAnimation forKey:@"shrinkAnimation"];
//회전
CABasicAnimation* spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spinAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
spinAnimation.toValue = [NSNumber numberWithFloat:M_PI];
[theView.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
// fade out 
CABasicAnimation* fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
fadeAnimation.toValue = [NSNumber numberWithFloat:0.0f];
[theView.layer addAnimation:fadeAnimation forKey:@"fadeAnimation"];
[CATransaction commit];
}

@end

2011년 5월 25일 수요일

iphone UIView 애니메이션 적용하기

//
//  SampleDay8_1ViewController.h
//  SampleDay8-1
//
//  Created by bit on 11. 5. 25..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#define kSegmentedControlTag 11
#define kBgViewTag 100
#define kWhiteViewTag 101
#define kGrayViewTag 102

#import

@interface SampleDay8_1ViewController : UIViewController {

}

@end



//
//  SampleDay8_1ViewController.m
//  SampleDay8-1
//
//  Created by bit on 11. 5. 25..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay8_1ViewController.h"

@interface SampleDay8_1ViewController (Private) 

-(IBAction)segmentValueChanged:(id)sender;

@end



@implementation SampleDay8_1ViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
UISegmentedControl *segment = (UISegmentedControl*)[self.view viewWithTag:kSegmentedControlTag];
[segment addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
}


/*
// 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];
}

-(IBAction)segmentValueChanged:(id)sender {

NSLog(@"call segmentValueChanged() -- value = ");

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.5f];
UIView *bgView = [self.view viewWithTag:kBgViewTag];
UISegmentedControl *segmentControl = (UISegmentedControl*)sender;
switch (segmentControl.selectedSegmentIndex) {
case 0:
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:bgView cache:YES];
break;
case 1:
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:bgView cache:YES];
break;
case 2:
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:bgView cache:YES];
break;
case 3:
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:bgView cache:YES];
break;
default:
break;
}
NSInteger whiteViewIndex = [bgView.subviews indexOfObject:[bgView viewWithTag:kWhiteViewTag]];
NSInteger grayViewIndex = [bgView.subviews indexOfObject:[bgView viewWithTag:kGrayViewTag]];
[bgView exchangeSubviewAtIndex:whiteViewIndex withSubviewAtIndex:grayViewIndex];
[UIView commitAnimations];
}


@end




iphone 애니메이션 기초


1. IBOutlet 을 사용하지 않고 태그값을 이용해서 불러오는 방법 

//
//  SampleDay8ViewController.m
//  SampleDay8
//
//  Created by bit on 11. 5. 25..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SampleDay8ViewController.h"

@implementation SampleDay8ViewController

@synthesize mSwitch;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
UIImageView *imageView = (UIImageView*)[self.view viewWithTag:100];
[imageView setImage:[UIImage imageNamed:@"play01.png"]];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:10];
for (int i=0; i<3; i++) {
[images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"play%02d.png", i+1]]];
}
imageView.animationImages = images;
imageView.animationDuration = 0.75f;
imageView.animationRepeatCount = 0;
//[images release];
}



/*
// 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];
}

-(IBAction)onValueChanged:(id)sender
{
1. IBOutlet 을 사용하지 않고 태그값을 이용해서 불러오는 방법 

UIImageView *imageView = (UIImageView*)[self.view viewWithTag:100];
if ( mSwitch.on == YES) {
[imageView startAnimating];
}
else {
[imageView stopAnimating];
}
}

@end