推荐相关不错的文章
1. http://www.189works.com/article-34872-1.html
(详细介绍UIImagePickerController类)
2. http://xyyk.iteye.com/blog/838038
主要讲解[popoverController presentPopoverFromRect:selectRect inView:self.viewpermittedArrowDirections:UIPopoverArrowDirectionAnyanimated:YES]; 这个方法
UIImagePickerController类
照相以及从相册中取得相片
1. In Iphone:
1) 声明及设置:
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *pickerImage = [[UIImagePickerControlleralloc] init];
pickerImage.delegate = self;
pickerImage.allowsEditing = YES;
pickerImage.sourceType = type;
[selfpresentModalViewController:pickerImage animated:YES];
[pickerImage release];
}
2) 实现其委托方法
#pragma mark UIImagePickerController delegate methods
//当用户照完像 或者 从相册中 选择完图片 之后 调用的方法
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
if (image != nil) {
//对获得的照片进行处理
}
[picker dismissModalViewControllerAnimated:YES];//设置相片选择工具消失
}
//当相片选择器 被取消的时候
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[selfadjustScrollViewHeight];
[picker dismissModalViewControllerAnimated:YES];//设置相片选择工具消失
}
2. In ipad:
(在ipad 中我们使用的是一个气泡框来 承载 相片选择器)
if ([UIImagePickerControllerisSourceTypeAvailable:type]) {
/*相片选择器1. 照相 2. 从相册获得 */
UIImagePickerController *pickerImage = [[UIImagePickerControlleralloc] init];
pickerImage.delegate = self;
pickerImage.allowsEditing = YES;
pickerImage.sourceType = type;
UIPopoverController *popover = [[UIPopoverControlleralloc] initWithContentViewController:pickerImage];
self.popoverController = popover;//popoverController 是本地声明的一个 popover
//Set the popoverController show From Rect-selectRect
CGRect selectRect;
selectRect = self.selectBg.frame; //selectBg 是一个我们气泡框 出现的位置的 参照物 (围绕着他)
[popoverControllerpresentPopoverFromRect:selectRect inView:self.viewpermittedArrowDirections:UIPopoverArrowDirectionAnyanimated:YES];
//上面这个方法看糊涂了吧 可以看一下这个 开头我们介绍的这篇文章 http://xyyk.iteye.com/blog/838038 (不想点连接 也可以看下边我贴出来的--借鉴一下 原版)
[popover release];
[pickerImage release];
}
2) 实现其委托方法
#pragma mark - UIImagePickerController delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
if (image != nil) {
//对获得的照片进行处理
}
[picker dismissModalViewControllerAnimated:YES];
//iPad take or get picture,touch "use" to dismiss popover.
[popover ControllerdismissPopoverAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
TodoViewController *contentViewController = [[TodoViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:contentViewController];
navigationController.contentSizeForViewInPopover = CGSizeMake(100, 100); //内容大小
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
popover.popoverContentSize = CGSizeMake(300, 300); //弹出窗口大小,如果屏幕画不下,会挤小的。这个值默认是320x1100
CGRect popoverRect = CGRectMake(200, 700, 10, 10);
[popover presentPopoverFromRect:popoverRect //popoverRect的中心点是用来画箭头的,如果中心点如果出了屏幕,系统会优化到窗口边缘
inView:self.view //上面的矩形坐标是以这个view为参考的
permittedArrowDirections:UIPopoverArrowDirectionDown //箭头方向
animated:YES];
[contentViewController release];
[navigationController release];
//最佳实践,使用哪个view做参考,就以哪个view的bounds送进去就好了,箭头自动指向这个view的中心