Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit dcdb4fc

Browse files
committed
Merge branch 'develop' for release/0.12
2 parents 0340efe + acbbb1c commit dcdb4fc

17 files changed

+1168
-976
lines changed

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- WPMediaPicker (0.11.3)
2+
- WPMediaPicker (0.12)
33

44
DEPENDENCIES:
55
- WPMediaPicker (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: 24a218bcd70cc9620c894129d8bc9d5e1935bd23
12+
WPMediaPicker: d4ce8e9db98b60ab44e7154151dbad135f8e7ff6
1313

1414
PODFILE CHECKSUM: 7855568785f801c5559f8e70856ad87de227dc95
1515

Example/WPMediaPicker.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
17F64FE01E6DDC74006C5A2B /* CustomPreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 17F64FDF1E6DDC74006C5A2B /* CustomPreviewViewController.m */; };
1011
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
1112
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; };
1213
6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
@@ -39,6 +40,8 @@
3940

4041
/* Begin PBXFileReference section */
4142
1120051BDDDC8A558883872E /* Pods-WPMediaPicker.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WPMediaPicker.release.xcconfig"; path = "Pods/Target Support Files/Pods-WPMediaPicker/Pods-WPMediaPicker.release.xcconfig"; sourceTree = "<group>"; };
43+
17F64FDE1E6DDC74006C5A2B /* CustomPreviewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomPreviewViewController.h; sourceTree = "<group>"; };
44+
17F64FDF1E6DDC74006C5A2B /* CustomPreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomPreviewViewController.m; sourceTree = "<group>"; };
4245
5709B45B57F590232B3E5DA7 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
4346
6003F58A195388D20070C39A /* WPMediaPicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WPMediaPicker.app; sourceTree = BUILT_PRODUCTS_DIR; };
4447
6003F58D195388D20070C39A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -140,6 +143,8 @@
140143
FFFFD8801A447E67000FC184 /* DemoViewController.m */,
141144
B5FF3BE81CAD8AB100C1D597 /* PostProcessingViewController.h */,
142145
B5FF3BE91CAD8AB100C1D597 /* PostProcessingViewController.m */,
146+
17F64FDE1E6DDC74006C5A2B /* CustomPreviewViewController.h */,
147+
17F64FDF1E6DDC74006C5A2B /* CustomPreviewViewController.m */,
143148
6003F59C195388D20070C39A /* AppDelegate.h */,
144149
6003F59D195388D20070C39A /* AppDelegate.m */,
145150
6003F5A8195388D20070C39A /* Images.xcassets */,
@@ -403,6 +408,7 @@
403408
isa = PBXSourcesBuildPhase;
404409
buildActionMask = 2147483647;
405410
files = (
411+
17F64FE01E6DDC74006C5A2B /* CustomPreviewViewController.m in Sources */,
406412
B5FF3BEA1CAD8AB100C1D597 /* PostProcessingViewController.m in Sources */,
407413
6003F59E195388D20070C39A /* AppDelegate.m in Sources */,
408414
FFFFD8811A447E67000FC184 /* DemoViewController.m in Sources */,

Example/WPMediaPicker/AppDelegate.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2828
//Configure navigation bar title text color
2929
[[UINavigationBar appearanceWhenContainedIn:[WPMediaPickerViewController class],nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} ];
3030
//Configure background color for media scroll view
31-
[[UICollectionView appearanceWhenContainedIn:[WPMediaCollectionViewController class],nil] setBackgroundColor:[UIColor colorWithRed:233/255.0f green:239/255.0f blue:243/255.0f alpha:1.0f]];
31+
[[UICollectionView appearanceWhenContainedIn:[WPMediaPickerViewController class],nil] setBackgroundColor:[UIColor colorWithRed:233/255.0f green:239/255.0f blue:243/255.0f alpha:1.0f]];
3232
//Configure background color for media cell while loading image.
33-
[[WPMediaCollectionViewCell appearanceWhenContainedIn:[WPMediaCollectionViewController class],nil] setBackgroundColor:[UIColor colorWithRed:243/255.0f green:246/255.0f blue:248/255.0f alpha:1.0f]];
33+
[[WPMediaCollectionViewCell appearanceWhenContainedIn:[WPMediaPickerViewController class],nil] setBackgroundColor:[UIColor colorWithRed:243/255.0f green:246/255.0f blue:248/255.0f alpha:1.0f]];
3434
//Configure color for activity indicator while loading media collection
35-
[[UIActivityIndicatorView appearanceWhenContainedIn:[WPMediaCollectionViewController class],nil] setColor:[UIColor grayColor]];
35+
[[UIActivityIndicatorView appearanceWhenContainedIn:[WPMediaPickerViewController class],nil] setColor:[UIColor grayColor]];
3636
return YES;
3737
}
3838

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@import UIKit;
2+
3+
#import <WPMediaPicker/WPMediaPicker.h>
4+
5+
@interface CustomPreviewViewController : UIViewController
6+
7+
@property (nonatomic, strong) id<WPMediaAsset> asset;
8+
9+
- (instancetype)initWithAsset:(id<WPMediaAsset>)asset;
10+
11+
@end
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#import "CustomPreviewViewController.h"
2+
3+
@interface CustomPreviewViewController ()
4+
@property (nonatomic, strong) UIImageView *imageView;
5+
@end
6+
7+
@implementation CustomPreviewViewController
8+
9+
- (instancetype)initWithAsset:(id<WPMediaAsset>)asset
10+
{
11+
if (self = [super initWithNibName:nil bundle:nil]) {
12+
_asset = asset;
13+
}
14+
15+
return self;
16+
}
17+
18+
- (void)viewDidLoad
19+
{
20+
[super viewDidLoad];
21+
22+
self.title = @"Preview";
23+
24+
self.view.backgroundColor = [UIColor greenColor];
25+
26+
[self addImageView];
27+
[self loadImage];
28+
}
29+
30+
- (void)addImageView
31+
{
32+
UIImageView *imageView = [UIImageView new];
33+
imageView.contentMode = UIViewContentModeScaleAspectFill;
34+
imageView.translatesAutoresizingMaskIntoConstraints = NO;
35+
[self.view addSubview:imageView];
36+
37+
[NSLayoutConstraint activateConstraints:@[
38+
[imageView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
39+
[imageView.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor],
40+
[imageView.widthAnchor constraintEqualToConstant:200],
41+
[imageView.heightAnchor constraintEqualToConstant:200],
42+
]];
43+
44+
self.imageView = imageView;
45+
}
46+
47+
- (void)loadImage
48+
{
49+
if ([self.asset assetType] == WPMediaTypeImage) {
50+
__weak __typeof__(self) weakSelf = self;
51+
[self.asset imageWithSize:CGSizeMake(200, 200) completionHandler:^(UIImage *result, NSError *error) {
52+
__typeof__(self) strongSelf = weakSelf;
53+
if (!strongSelf) {
54+
return;
55+
}
56+
dispatch_async(dispatch_get_main_queue(), ^{
57+
strongSelf.imageView.image = result;
58+
});
59+
}];
60+
}
61+
}
62+
63+
- (CGSize)preferredContentSize
64+
{
65+
return CGSizeMake(200, 200);
66+
}
67+
68+
@end

Example/WPMediaPicker/DemoViewController.m

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#import "DemoViewController.h"
2+
#import "CustomPreviewViewController.h"
23
#import "WPPHAssetDataSource.h"
34
#import "OptionsViewController.h"
45
#import "PostProcessingViewController.h"
56
#import <WPMediaPicker/WPMediaPicker.h>
67
#import <WPMediaPicker/WPMediaGroupTableViewCell.h>
8+
#import <WPMediaPicker/WPMediaPicker.h>
79

810
@interface DemoViewController () <WPMediaPickerViewControllerDelegate, OptionsViewControllerDelegate>
911

1012
@property (nonatomic, strong) NSArray * assets;
1113
@property (nonatomic, strong) NSDateFormatter * dateFormatter;
1214
@property (nonatomic, strong) id<WPMediaCollectionDataSource> customDataSource;
1315
@property (nonatomic, copy) NSDictionary *options;
16+
@property (nonatomic, strong) WPNavigationMediaPickerViewController *mediaPicker;
1417

1518
@end
1619

@@ -36,7 +39,8 @@ - (void)viewDidLoad
3639
MediaPickerOptionsShowCameraCapture:@(YES),
3740
MediaPickerOptionsAllowMultipleSelection:@(YES),
3841
MediaPickerOptionsPostProcessingStep:@(NO),
39-
MediaPickerOptionsFilterType:@(WPMediaTypeVideoOrImage)
42+
MediaPickerOptionsFilterType:@(WPMediaTypeVideoOrImage),
43+
MediaPickerOptionsCustomPreview:@(NO)
4044
};
4145

4246
}
@@ -113,7 +117,16 @@ - (void)mediaPickerController:(WPMediaPickerViewController *)picker didFinishPic
113117
[self dismissViewControllerAnimated:YES completion:nil];
114118
};
115119

116-
[picker showAfterViewController:postProcessingViewController];
120+
[self.mediaPicker showAfterViewController:postProcessingViewController];
121+
}
122+
123+
- (UIViewController *)mediaPickerController:(WPMediaPickerViewController *)picker previewViewControllerForAsset:(id<WPMediaAsset>)asset
124+
{
125+
if ([self.options[MediaPickerOptionsCustomPreview] boolValue] == false) {
126+
return nil;
127+
}
128+
129+
return [[CustomPreviewViewController alloc] initWithAsset:asset];
117130
}
118131

119132
#pragma - Actions
@@ -126,18 +139,18 @@ - (void) clearSelection:(id) sender
126139

127140
- (void) showPicker:(id) sender
128141
{
129-
WPMediaPickerViewController *mediaPicker = [[WPMediaPickerViewController alloc] init];
130-
mediaPicker.delegate = self;
131-
mediaPicker.showMostRecentFirst = [self.options[MediaPickerOptionsShowMostRecentFirst] boolValue];
132-
mediaPicker.allowCaptureOfMedia = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
133-
mediaPicker.preferFrontCamera = [self.options[MediaPickerOptionsPreferFrontCamera] boolValue];
134-
mediaPicker.allowMultipleSelection = [self.options[MediaPickerOptionsAllowMultipleSelection] boolValue];
135-
mediaPicker.filter = [self.options[MediaPickerOptionsFilterType] intValue];
136-
mediaPicker.modalPresentationStyle = UIModalPresentationPopover;
137-
UIPopoverPresentationController *ppc = mediaPicker.popoverPresentationController;
142+
self.mediaPicker = [[WPNavigationMediaPickerViewController alloc] init];
143+
self.mediaPicker.delegate = self;
144+
self.mediaPicker.showMostRecentFirst = [self.options[MediaPickerOptionsShowMostRecentFirst] boolValue];
145+
self.mediaPicker.allowCaptureOfMedia = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
146+
self.mediaPicker.preferFrontCamera = [self.options[MediaPickerOptionsPreferFrontCamera] boolValue];
147+
self.mediaPicker.allowMultipleSelection = [self.options[MediaPickerOptionsAllowMultipleSelection] boolValue];
148+
self.mediaPicker.filter = [self.options[MediaPickerOptionsFilterType] intValue];
149+
self.mediaPicker.modalPresentationStyle = UIModalPresentationPopover;
150+
UIPopoverPresentationController *ppc = self.mediaPicker.popoverPresentationController;
138151
ppc.barButtonItem = sender;
139152

140-
[self presentViewController:mediaPicker animated:YES completion:nil];
153+
[self presentViewController:self.mediaPicker animated:YES completion:nil];
141154
}
142155

143156
- (void) showOptions:(id) sender

Example/WPMediaPicker/OptionsViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern NSString const *MediaPickerOptionsPreferFrontCamera;
66
extern NSString const *MediaPickerOptionsAllowMultipleSelection;
77
extern NSString const *MediaPickerOptionsPostProcessingStep;
88
extern NSString const *MediaPickerOptionsFilterType;
9+
extern NSString const *MediaPickerOptionsCustomPreview;
910

1011
@class OptionsViewController;
1112

Example/WPMediaPicker/OptionsViewController.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
NSString const *MediaPickerOptionsAllowMultipleSelection = @"MediaPickerOptionsAllowMultipleSelection";
88
NSString const *MediaPickerOptionsPostProcessingStep = @"MediaPickerOptionsPostProcessingStep";
99
NSString const *MediaPickerOptionsFilterType = @"MediaPickerOptionsFilterType";
10+
NSString const *MediaPickerOptionsCustomPreview = @"MediaPickerOptionsCustomPreview";
1011

1112
typedef NS_ENUM(NSInteger, OptionsViewControllerCell){
1213
OptionsViewControllerCellShowMostRecentFirst,
@@ -15,6 +16,7 @@ typedef NS_ENUM(NSInteger, OptionsViewControllerCell){
1516
OptionsViewControllerCellAllowMultipleSelection,
1617
OptionsViewControllerCellPostProcessingStep,
1718
OptionsViewControllerCellMediaType,
19+
OptionsViewControllerCellCustomPreview,
1820
OptionsViewControllerCellTotal
1921
};
2022

@@ -26,6 +28,7 @@ @interface OptionsViewController ()
2628
@property (nonatomic, strong) UITableViewCell *allowMultipleSelectionCell;
2729
@property (nonatomic, strong) UITableViewCell *postProcessingStepCell;
2830
@property (nonatomic, strong) UITableViewCell *filterMediaCell;
31+
@property (nonatomic, strong) UITableViewCell *customPreviewCell;
2932

3033
@end
3134

@@ -70,6 +73,11 @@ - (void)viewDidLoad
7073
self.filterMediaCell.accessoryView = segment;
7174
segment.selectedSegmentIndex = [self.options[MediaPickerOptionsFilterType] intValue];
7275
self.filterMediaCell.textLabel.text = @"Media Type";
76+
77+
self.customPreviewCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
78+
self.customPreviewCell.accessoryView = [[UISwitch alloc] init];
79+
((UISwitch *)self.customPreviewCell.accessoryView).on = [self.options[MediaPickerOptionsCustomPreview] boolValue];
80+
self.customPreviewCell.textLabel.text = @"Use Custom Preview Controller";
7381
}
7482

7583
#pragma mark - Table view data source
@@ -105,6 +113,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
105113
case OptionsViewControllerCellMediaType:
106114
return self.filterMediaCell;
107115
break;
116+
case OptionsViewControllerCellCustomPreview:
117+
return self.customPreviewCell;
118+
break;
108119
default:
109120
break;
110121
}
@@ -122,6 +133,7 @@ - (void)done:(id) sender
122133
MediaPickerOptionsAllowMultipleSelection:@(((UISwitch *)self.allowMultipleSelectionCell.accessoryView).on),
123134
MediaPickerOptionsPostProcessingStep:@(((UISwitch *)self.postProcessingStepCell.accessoryView).on),
124135
MediaPickerOptionsFilterType:@(((UISegmentedControl *)self.filterMediaCell.accessoryView).selectedSegmentIndex),
136+
MediaPickerOptionsCustomPreview:@(((UISwitch *)self.customPreviewCell.accessoryView).on),
125137
};
126138

127139
[delegate optionsViewController:self changed:newOptions];

0 commit comments

Comments
 (0)