重定義 UIImagePickerController

今天想實現一個類似Path 的Photo Picker的效果,沒有Cancel按鈕,取而代之的是添加一個從相冊獲取的按鈕,要知道這在官方的SDK裏面是沒有。


開始之前,先做下功課,找到幾個相關的文章

  1. http://blog.airsource.co.uk/index.php/2008/11/11/views-of-uiimagepickercontroller/
  2. http://www.cocoachina.com/bbs/read.php?tid-11664-page-1.html>

以下的這個框架圖對接下來的工作會很有幫助

紅色的高亮部分是從屏幕上看到的照片的預覽圖,除了這個之外,他上面的view都可以去掉。

要想編輯這些個View,得先找到他們,這裏給出了個方法

#pragma mark get/show the UIView we want
//Find the view we want in camera structure.
-(UIView *)findView:(UIView *)aView withName:(NSString *)name{
	Class cl = [aView class];
	NSString *desc = [cl description];

	if ([name isEqualToString:desc])
		return aView;

	for (NSUInteger i = 0; i < [aView.subviews count]; i++)
	{
		UIView *subView = [aView.subviews objectAtIndex:i];
		subView = [self findView:subView withName:name];
		if (subView)
			return subView;
	}
	return nil;
}
怎麼用,下面這段代碼裏給出了比較詳細的例子

-(void)addSomeElements:(UIViewController *)viewController{
	//Add the motion view here, PLCameraView and picker.view are both OK
	UIView *PLCameraView=[self findView:viewController.view withName:@"PLCameraView"];
	[PLCameraView addSubview:touchView];//[viewController.view addSubview:self.touchView];//You can also try this one.

	//Add button for Timer capture
	[PLCameraView addSubview:timerButton];
	[PLCameraView addSubview:continuousButton];

	[PLCameraView insertSubview:bottomBarImageView atIndex:1];

	//Used to hide the transiton, last added view will be the topest layer
	[PLCameraView addSubview:myTransitionView];

	//Add label to cropOverlay
	UIView *cropOverlay=[self findView:PLCameraView withName:@"PLCropOverlay"];
	[cropOverlay addSubview:lblWatermark];

	//Get Bottom Bar
	UIView *bottomBar=[self findView:PLCameraView withName:@"PLCropOverlayBottomBar"];

	//Get ImageView For Save
	UIImageView *bottomBarImageForSave = [bottomBar.subviews objectAtIndex:0];

	//Get Button 0
	UIButton *retakeButton=[bottomBarImageForSave.subviews objectAtIndex:0];
	[retakeButton setTitle:@"重拍" forState:UIControlStateNormal];

	//Get Button 1
	UIButton *useButton=[bottomBarImageForSave.subviews objectAtIndex:1];
	[useButton setTitle:@"保存" forState:UIControlStateNormal];

	//Get ImageView For Camera
	UIImageView *bottomBarImageForCamera = [bottomBar.subviews objectAtIndex:1];

	//Set Bottom Bar Image
	UIImage *image=[[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"BottomBar.png"]];
	bottomBarImageForCamera.image=image;
	[image release];

	//Get Button 0(The Capture Button)
	UIButton *cameraButton=[bottomBarImageForCamera.subviews objectAtIndex:0];
	[cameraButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];

	//Get Button 1
	UIButton *cancelButton=[bottomBarImageForCamera.subviews objectAtIndex:1];
	[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
	[cancelButton addTarget:self action:@selector(hideTouchView) forControlEvents:UIControlEventTouchUpInside];
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章