點擊按鈕讓麥克風錄音,再次點擊完成錄音
viewcontroller.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
{
AVAudioRecorder *audioRecorder;
AVAudioPlayer *audioPlayer;
}
@end
Will 發表在 痞客邦 留言(0) 人氣(222)
此範例為點及按鈕開啟相機,
使用相機拍照顯示在imageview後並存入相簿
#import "ViewController.h"
@interface ViewController ()
- (IBAction)takePictureButton:(id)sender;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer * tapPress = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tapPress.numberOfTapsRequired = 1;
[_myImageView setUserInteractionEnabled:YES];
[_myImageView addGestureRecognizer:tapPress];
}
-(void)handleTap:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"cancle" destructiveButtonTitle:nil otherButtonTitles:@"save to album", nil];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0 )
{
UIImageWriteToSavedPhotosAlbum( _myImageView.image , self, @selector(image:didFinishSavingWithError:comtextInfo:), nil);
}
}
-(void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if(!error){
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"save to album" message:@"save to album already" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertView show];
}else{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"save to album" message:@"failed to save" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertView show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)takePictureButton:(id)sender {
UIImagePickerController * ipc = [[UIImagePickerController alloc]init];
//確認裝置是否有相機可使用
if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
//確認是否有後方鏡頭
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
ipc.cameraDevice = UIImagePickerControllerCameraDeviceRear;
//設定是拍照還是錄影
ipc.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
ipc.allowsEditing = YES;
ipc.delegate = self;
[self presentViewController:ipc animated:YES completion:nil];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//取得目前拿到的資料型態
NSString *mediaType = [ info objectForKey:UIImagePickerControllerMediaType];
//目前照相的畫面關閉
[picker dismissViewControllerAnimated:YES completion:nil];
//資料型態必須為一般的照片
if([mediaType isEqualToString:@"public.image"])
{
//照片是否編輯過
if([info objectForKey:UIImagePickerControllerEditedImage])
{
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
_myImageView.image = editedImage;
}else{
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
_myImageView.image = originalImage;
}
}
}
@end
Will 發表在 痞客邦 留言(0) 人氣(979)
本範例為點擊按鈕播放影片,步驟如下
1. 建立專案後加入MediaPlayer.framework
2. storyboard加入一顆按鈕來觸發影片播放
3. 將要播放的影片網址複製
Will 發表在 痞客邦 留言(0) 人氣(251)
本範例為點擊按鈕播放影片,步驟如下
1. 建立專案後加入MediaPlayer.framework
2. storyboard加入一顆按鈕來觸發影片播放
3. 將要播放的影片copy進專案中
Will 發表在 痞客邦 留言(0) 人氣(196)
此範例為點擊按鈕觸發點擊按扭播放音樂,
順帶一提此程式需要在實機上執行才有效過, 模擬器則無法測試
Step1. 創建一個新專案, 加入一顆按鈕, 點擊可產生播放音樂, 將音樂檔案加入專案, 並建立Button與程式之關聯性
Step2. 加入AVFoundation.framework, 並#import <AVFoundation/AVFoundation.h>
Will 發表在 痞客邦 留言(0) 人氣(111)
此範例為點擊按鈕觸發點擊按扭播放音效效果,
順帶一提此程式需要在實機上執行才有效過, 模擬器則無法測試
Step1. 創建一個新專案, 加入一顆按鈕, 點擊可產生震動效果, 並建立Button與程式之關聯性
Step2. 加入AudioToolbox.framework, 並#import <AudioToolBox/AudioToolbox.h>
Will 發表在 痞客邦 留言(0) 人氣(516)
此範例為點擊按鈕觸發震動效果,
順帶一提此程式需要在實機上執行才有效過, 模擬器則無法測試
Step1. 創建一個新專案, 加入一顆按鈕, 點擊可產生震動效果, 並建立Button與程式之關聯性
Step2. 加入AudioToolbox.framework, 並#import <AudioToolBox/AudioToolbox.h>
Will 發表在 痞客邦 留言(0) 人氣(1,061)