Commit b12a93ed authored by mei's avatar mei

调用相册已完成 由于相机模拟器不支持 所以调用相机需真机调试

parent 58637248
......@@ -7,8 +7,19 @@
//
#import "BaseViewController.h"
#import "DeviceDirectionManager.h"
@protocol AddCustomPicturedelegate <NSObject>
@required
//回调
- (void)addCustomPictureImage:(UIImage *)image ;
@end
@interface CameraView : BaseViewController<UIGestureRecognizerDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (nonatomic,assign) id<AddCustomPicturedelegate> delegate;
@property(nonatomic,strong)UIView *subView;
@property(nonatomic,strong)UIPopoverController *popoverController;
@property(nonatomic,strong)UIImage *customImage;
@end
......@@ -26,7 +26,6 @@
_imagePickerController.delegate = self;
_imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
_imagePickerController.allowsEditing = YES;
// [_imagePickerController supportedInterfaceOrientations];
[self initView];
// Do any additional setup after loading the view.
}
......@@ -74,24 +73,13 @@
switch (sender.tag) {
case 101://拍照
{
// UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// if ([UIImagePickerController isSourceTypeAvailable:
// UIImagePickerControllerSourceTypePhotoLibrary]) {
// imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// imagePicker.delegate = self;
// [imagePicker setAllowsEditing:YES];
// UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
// self.popoverController = popover;
// [self presentViewController:imagePicker animated:YES completion:nil];
//// [self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 800, 500) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
//
// }
// [self selectImageFromAlbum];
[self selectImageFromCamera];
}
break;
case 102://从相册中选取
{
[self selectImageFromAlbum];
}
break;
case 103://取消
......@@ -110,71 +98,47 @@
- (void)selectImageFromCamera
{
_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
//录制视频时长,默认10s
_imagePickerController.videoMaximumDuration = 15;
//相机类型(拍照、录像...)字符串需要做相应的类型转换
_imagePickerController.mediaTypes = @[(NSString *)kUTTypeMovie,(NSString *)kUTTypeImage];
//视频上传质量
//UIImagePickerControllerQualityTypeHigh高清
//UIImagePickerControllerQualityTypeMedium中等质量
//UIImagePickerControllerQualityTypeLow低质量
//UIImagePickerControllerQualityType640x480
_imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;
//设置摄像头模式(拍照,录制视频)为录像模式
_imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
//在打开相机之前,设置屏幕为支持竖屏
[DeviceDirectionManager instance].isHorizontal=YES;
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
#pragma mark 从相册获取图片或视频
#pragma mark 从相册获取图片
- (void)selectImageFromAlbum
{
//NSLog(@"相册");
_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//在打开相册之前,设置屏幕为支持竖屏
[DeviceDirectionManager instance].isHorizontal=YES;
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
#pragma mark UIImagePickerControllerDelegate
//该代理方法仅适用于只选取图片时
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary<NSString *,id> *)editingInfo {
NSLog(@"选择完毕----image:%@-----info:%@",image,editingInfo);
}
//适用获取所有媒体资源,只需判断资源类型
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
//判断资源类型
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]){
//如果是图片
// self.imageView.image = info[UIImagePickerControllerEditedImage];
// //压缩图片
// NSData *fileData = UIImageJPEGRepresentation(self.imageView.image, 1.0);
// //保存图片至相册
// UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
// //上传图片
// [self uploadImageWithData:fileData];
self.customImage= info[UIImagePickerControllerEditedImage];
if ([self.delegate respondsToSelector:@selector(addCustomPictureImage:)]) {
[self.delegate addCustomPictureImage:self.customImage];
}
}else{
//如果是视频
NSURL *url = info[UIImagePickerControllerMediaURL];
//播放视频
// _moviePlayer.contentURL = url;
// [_moviePlayer play];
//保存视频至相册(异步线程)
NSString *urlStr = [url path];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(urlStr)) {
UISaveVideoAtPathToSavedPhotosAlbum(urlStr, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
});
NSData *videoData = [NSData dataWithContentsOfURL:url];
//视频上传
// [self uploadVideoWithData:videoData];
}
[self dismissViewControllerAnimated:YES completion:nil];
[DeviceDirectionManager instance].isHorizontal=NO;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
[DeviceDirectionManager instance].isHorizontal=NO;
}
#pragma mark 图片保存完毕的回调
- (void) image: (UIImage *) image didFinishSavingWithError:(NSError *) error contextInfo: (void *)contextInf{
......@@ -189,11 +153,6 @@
NSLog(@"视频保存成功.");
}
}
//支持横屏
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
//取消按钮
-(void)DismissScreenView
{
......
......@@ -24,7 +24,7 @@
@end
@interface FollowHeartViewController : BaseViewController<LeftViewBtnClickdelegate,RightViewBtnClickdelegate,FootViewBtnClickdelegate,UIGestureRecognizerDelegate,AddSecenePicturedelegate,AddProductPicturedelegate,SharePicturedelegate>
@interface FollowHeartViewController : BaseViewController<LeftViewBtnClickdelegate,RightViewBtnClickdelegate,FootViewBtnClickdelegate,UIGestureRecognizerDelegate,AddSecenePicturedelegate,AddProductPicturedelegate,SharePicturedelegate,AddCustomPicturedelegate>
@property (nonatomic,assign) id<FollowHeartViewAddpicturedelegate> delegate;
@property (nonatomic,strong) LeftSubView *leftSubView;
@property (nonatomic,strong) RightSubView *rightSubView;
......
......@@ -112,25 +112,24 @@
{
self.cameraView=[[CameraView alloc]init];
self.cameraView.view.backgroundColor=[UIColor clearColor];
// // self.cameraView.delegate=self;
self.cameraView.delegate=self;
[self.view addSubview:self.cameraView.view];
// [SHARED_APPDELEGATE.window.rootViewController.view addSubview: self.cameraView.view];
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"ceshi" message:@"shide " preferredStyle:UIAlertControllerStyleAlert];
// [self presentViewController:alertController animated:YES completion:nil];
}
//场景赋图回调
//自定义场景附图回调
- (void)addCustomPictureImage:(UIImage *)image
{
[self.footSubView addFootSubViewImage:image];
self.backGroundImageView.image=image;
}
//添加场景图
- (void)resetSuperBackGroundImage:(UIImage*)image
{
self.backGroundImageView.image=image;
}
//产品附图回调
//添加产品图
- (void)resetSubProductImage:(UIImage*)image productModel:(NSMutableArray *)productModel
{
ImageCropperView *cropper=[[ImageCropperView alloc]initWithFrame:CGRectMake(400, 300, 300, 300)];
// cropper.layer.borderWidth = 1.0;
// cropper.layer.borderColor = [UIColor blueColor].CGColor;
cropper.image = image;
[self.view addSubview:cropper];
}
......
......@@ -100,8 +100,8 @@
#pragma mark -登陆
- (IBAction)LoginButtonClick:(UIButton *)sender {
// [self SetTheRootViewController];
// return;
[self SetTheRootViewController];
return;
if (self.userName.text.length == 0) {
[self ErrorMBProgressView:@"用户名不能为空"];
......
......@@ -9,5 +9,5 @@
#import <Foundation/Foundation.h>
@interface NSObject (UIImagePickerController)
- (NSUInteger)supportedInterfaceOrientations ;
@end
......@@ -10,10 +10,10 @@
@implementation NSObject (UIImagePickerController)
//指定 UIImagePickerController只支持横屏
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
//-(NSUInteger)supportedInterfaceOrientations
//{
// return UIInterfaceOrientationMaskLandscape;
//}
//设置状态栏
-(UIStatusBarStyle)preferredStatusBarStyle
{
......@@ -23,4 +23,12 @@
{
return YES;
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
@end
//
// DeviceDirectionManager.h
// Lighting
//
// Created by mac on 16/5/26.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DeviceDirectionManager : NSObject
@property (nonatomic, assign) BOOL isHorizontal;//是否是横屏
+ (DeviceDirectionManager *)instance;
@end
//
// DeviceDirectionManager.m
// Lighting
//
// Created by mac on 16/5/26.
// Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//
#import "DeviceDirectionManager.h"
//支持横竖屏单例
@implementation DeviceDirectionManager
+ (DeviceDirectionManager *)instance{
static dispatch_once_t onceToken;
static DeviceDirectionManager *_instance = nil;
dispatch_once(&onceToken, ^{
_instance = [[DeviceDirectionManager alloc] init];
});
assert(_instance!=nil);
return _instance;
}
@end
......@@ -23,6 +23,7 @@
04F9EE1B1CF22B5900BD729F /* ShoppingCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F9EE1A1CF22B5900BD729F /* ShoppingCell.m */; };
04F9EE1E1CF25F7300BD729F /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04F9EE1D1CF25F7300BD729F /* ShareViewController.m */; };
04F9EE221CF27B1D00BD729F /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F9EE211CF27B1D00BD729F /* CoreTelephony.framework */; };
04FCB1A41CF60A8F0056093B /* DeviceDirectionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FCB1A31CF60A8F0056093B /* DeviceDirectionManager.m */; };
060D397C1CE45CFE0082AECD /* ImageCropperView.m in Sources */ = {isa = PBXBuildFile; fileRef = 060D39791CE45CFE0082AECD /* ImageCropperView.m */; };
060D397D1CE45CFE0082AECD /* UIImage+Rotation.m in Sources */ = {isa = PBXBuildFile; fileRef = 060D397B1CE45CFE0082AECD /* UIImage+Rotation.m */; };
2906B5D71CD89246000849B4 /* ClientDetailsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2906B5D61CD89246000849B4 /* ClientDetailsTableViewCell.m */; };
......@@ -167,6 +168,8 @@
04F9EE1D1CF25F7300BD729F /* ShareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = "<group>"; };
04F9EE1F1CF27AF900BD729F /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
04F9EE211CF27B1D00BD729F /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; };
04FCB1A21CF60A8F0056093B /* DeviceDirectionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeviceDirectionManager.h; sourceTree = "<group>"; };
04FCB1A31CF60A8F0056093B /* DeviceDirectionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DeviceDirectionManager.m; sourceTree = "<group>"; };
060D39781CE45CFE0082AECD /* ImageCropperView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCropperView.h; sourceTree = "<group>"; };
060D39791CE45CFE0082AECD /* ImageCropperView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCropperView.m; sourceTree = "<group>"; };
060D397A1CE45CFE0082AECD /* UIImage+Rotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Rotation.h"; sourceTree = "<group>"; };
......@@ -488,6 +491,8 @@
060D39791CE45CFE0082AECD /* ImageCropperView.m */,
060D397A1CE45CFE0082AECD /* UIImage+Rotation.h */,
060D397B1CE45CFE0082AECD /* UIImage+Rotation.m */,
04FCB1A21CF60A8F0056093B /* DeviceDirectionManager.h */,
04FCB1A31CF60A8F0056093B /* DeviceDirectionManager.m */,
);
path = tools;
sourceTree = "<group>";
......@@ -1447,6 +1452,7 @@
29BFBD8F1CE44BA900C238FB /* goodsDetailsSectionview.m in Sources */,
294CF0EC1CEDCF480055F1D8 /* PromptinformationView.m in Sources */,
290887131CE5DF16000B7097 /* ShopcarModel.m in Sources */,
04FCB1A41CF60A8F0056093B /* DeviceDirectionManager.m in Sources */,
29BB27681CD9D38E009A0813 /* AllpriceTableViewCell.m in Sources */,
29BB27771CD9DFBA009A0813 /* ProductLibraryViewController.m in Sources */,
04F9EE181CF2235000BD729F /* ShoppingView.m in Sources */,
......
......@@ -49,7 +49,7 @@
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window;
@end
......@@ -8,6 +8,7 @@
#import "AppDelegate.h"
#import "LoginViewController.h"
#import "DeviceDirectionManager.h"
@interface AppDelegate ()
@end
......@@ -24,7 +25,23 @@
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
//判断是否是横屏
if ( [[DeviceDirectionManager instance] isHorizontal]) {
return UIInterfaceOrientationMaskAll ;
}else{
return UIInterfaceOrientationMaskLandscape;
}
}
#pragma mark -设置根视图
- (void)RootViewcontroller
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment