Skip to content

Commit 03ff721

Browse files
committed
Support for iPad
1 parent 9f97b79 commit 03ff721

10 files changed

Lines changed: 203 additions & 51 deletions

File tree

‎REActivityViewController/REActivityView.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@interface REActivityView : UIView <UIScrollViewDelegate> {
1313
UIPageControl *_pageControl;
14+
UIButton *_cancelButton;
1415
}
1516

1617
@property (strong, nonatomic) UIImageView *backgroundImageView;

‎REActivityViewController/REActivityView.m‎

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,38 @@ - (id)initWithFrame:(CGRect)frame activities:(NSArray *)activities
1515
{
1616
self = [super initWithFrame:frame];
1717
if (self) {
18+
self.clipsToBounds = YES;
1819
_activities = activities;
19-
_backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, frame.size.height - 417, frame.size.width, 417)];
20-
_backgroundImageView.image = [UIImage imageNamed:@"Background"];
21-
_backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
22-
[self addSubview:_backgroundImageView];
2320

24-
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 39, frame.size.width, 300)];
21+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
22+
_backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 417)];
23+
_backgroundImageView.image = [UIImage imageNamed:@"Background"];
24+
_backgroundImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
25+
[self addSubview:_backgroundImageView];
26+
}
27+
28+
29+
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 39, frame.size.width, self.frame.size.height - 104)];
2530
_scrollView.showsHorizontalScrollIndicator = NO;
2631
_scrollView.showsVerticalScrollIndicator = NO;
2732
_scrollView.delegate = self;
28-
// _scrollView.backgroundColor = [UIColor blackColor];
33+
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
34+
// _scrollView.backgroundColor = [UIColor blueColor];
2935
[self addSubview:_scrollView];
3036

3137
NSInteger index = 0;
3238
NSInteger row = -1;
3339
NSInteger page = -1;
3440
for (REActivity *activity in _activities) {
35-
NSInteger col = index%3;
41+
NSInteger col;
42+
43+
col = index%3;
3644
if (index % 3 == 0) row++;
3745
if (index % 9 == 0) {
3846
row = 0;
3947
page++;
4048
}
41-
NSLog(@"index = %i", index % 9);
49+
// NSLog(@"index = %i", index % 9);
4250
UIView *view = [self viewForActivity:activity
4351
index:index
4452
x:(20 + col*80 + col*20) + page * frame.size.width
@@ -49,24 +57,25 @@ - (id)initWithFrame:(CGRect)frame activities:(NSArray *)activities
4957
_scrollView.contentSize = CGSizeMake((page +1) * frame.size.width, _scrollView.frame.size.height);
5058
_scrollView.pagingEnabled = YES;
5159

52-
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 327, frame.size.width, 10)];
60+
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, frame.size.height - (UIInterfaceOrientationIsPortrait([UIDevice currentDevice].orientation) ? 90 : 86), frame.size.width, 10)];
5361
_pageControl.numberOfPages = page + 1;
5462
[_pageControl addTarget:self action:@selector(pageControlValueChanged:) forControlEvents:UIControlEventValueChanged];
5563
[self addSubview:_pageControl];
5664

5765
if (_pageControl.numberOfPages <= 1)
5866
_pageControl.hidden = YES;
5967

60-
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
61-
[button setBackgroundImage:[[UIImage imageNamed:@"Button"] stretchableImageWithLeftCapWidth:22 topCapHeight:47] forState:UIControlStateNormal];
62-
button.frame = CGRectMake(22, 352, 276, 47);
63-
[button setTitle:@"Cancel" forState:UIControlStateNormal];
64-
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
65-
[button setTitleShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4] forState:UIControlStateNormal];
66-
[button.titleLabel setShadowOffset:CGSizeMake(0, -1)];
67-
[button.titleLabel setFont:[UIFont boldSystemFontOfSize:19]];
68-
[button addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
69-
[self addSubview:button];
68+
_cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
69+
[_cancelButton setBackgroundImage:[[UIImage imageNamed:@"Button"] stretchableImageWithLeftCapWidth:22 topCapHeight:47] forState:UIControlStateNormal];
70+
_cancelButton.frame = CGRectMake(22, 352, 276, 47);
71+
[_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
72+
[_cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
73+
[_cancelButton setTitleShadowColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4] forState:UIControlStateNormal];
74+
[_cancelButton.titleLabel setShadowOffset:CGSizeMake(0, -1)];
75+
[_cancelButton.titleLabel setFont:[UIFont boldSystemFontOfSize:19]];
76+
[_cancelButton addTarget:self action:@selector(cancelButtonPressed) forControlEvents:UIControlEventTouchUpInside];
77+
// _cancelButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
78+
[self addSubview:_cancelButton];
7079
}
7180
return self;
7281
}
@@ -101,6 +110,18 @@ - (UIView *)viewForActivity:(REActivity *)activity index:(NSInteger)index x:(NSI
101110
return view;
102111
}
103112

113+
- (void)layoutSubviews
114+
{
115+
[super layoutSubviews];
116+
117+
CGRect frame = _cancelButton.frame;
118+
frame.origin.y = self.frame.size.height - 47 - 16;
119+
frame.origin.x = (self.frame.size.width - frame.size.width) / 2.0f;
120+
_cancelButton.frame = frame;
121+
122+
//_scrollView.frame = CGRectMake(_scrollView.frame.origin.x, _scrollView.frame.origin.y, _scrollView.frame.size.width, self.frame.size.height - 104);
123+
}
124+
104125
#pragma mark -
105126
#pragma mark Button action
106127

‎REActivityViewController/REActivityViewController.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
@property (strong, readonly, nonatomic) NSArray *activities;
2323
@property (strong, nonatomic) NSDictionary *userInfo;
2424
@property (strong, nonatomic) REActivityView *activityView;
25+
@property (weak, nonatomic) UIPopoverController *presentingPopoverController;
26+
@property (weak, nonatomic) UIViewController *presentingController;
2527

26-
- (id)initWithActivities:(NSArray *)activities;
27-
- (NSInteger)height;
28+
- (id)initWithViewController:(UIViewController *)viewController activities:(NSArray *)activities;
2829

2930
@end

‎REActivityViewController/REActivityViewController.m‎

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,56 @@
1111

1212
@interface REActivityViewController ()
1313

14+
- (NSInteger)height;
15+
1416
@end
1517

1618
@implementation REActivityViewController
1719

18-
- (id)initWithActivities:(NSArray *)activities
20+
- (id)initWithViewController:(UIViewController *)viewController activities:(NSArray *)activities
1921
{
2022
self = [super init];
2123
if (self) {
22-
_backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
23-
_backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
24-
_backgroundView.backgroundColor = [UIColor blackColor];
25-
_backgroundView.alpha = 0;
26-
[self.view addSubview:_backgroundView];
24+
self.view.frame = CGRectMake(0, 0, 320, 417);
25+
self.presentingController = viewController;
26+
27+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
28+
_backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
29+
_backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
30+
_backgroundView.backgroundColor = [UIColor blackColor];
31+
_backgroundView.alpha = 0;
32+
[self.view addSubview:_backgroundView];
33+
}
2734

2835
_activities = activities;
29-
_activityView = [[REActivityView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, self.view.frame.size.width, 417) activities:activities];
36+
_activityView = [[REActivityView alloc] initWithFrame:CGRectMake(0, UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? [UIScreen mainScreen].bounds.size.height : 0, self.view.frame.size.width, self.height) activities:activities];
37+
_activityView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
3038
_activityView.activityViewController = self;
3139
[self.view addSubview:_activityView];
40+
41+
self.contentSizeForViewInPopover = CGSizeMake(320, self.height - 60);
3242
}
3343
return self;
3444
}
3545

3646
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
3747
{
38-
[UIView animateWithDuration:0.4 animations:^{
39-
_backgroundView.alpha = 0;
40-
CGRect frame = _activityView.frame;
41-
frame.origin.y = [UIScreen mainScreen].bounds.size.height;
42-
_activityView.frame = frame;
43-
} completion:^(BOOL finished) {
44-
[super dismissViewControllerAnimated:NO completion:completion];
45-
}];
48+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
49+
[UIView animateWithDuration:0.4 animations:^{
50+
_backgroundView.alpha = 0;
51+
CGRect frame = _activityView.frame;
52+
frame.origin.y = [UIScreen mainScreen].bounds.size.height;
53+
_activityView.frame = frame;
54+
} completion:^(BOOL finished) {
55+
[super dismissViewControllerAnimated:NO completion:completion];
56+
}];
57+
} else {
58+
[self.presentingPopoverController dismissPopoverAnimated:YES];
59+
[self performBlock:^{
60+
if (completion)
61+
completion();
62+
} afterDelay:0.4];
63+
}
4664
}
4765

4866
- (void)performBlock:(void (^)(void))block afterDelay:(NSTimeInterval)delay
@@ -59,19 +77,29 @@ - (void)runBlockAfterDelay:(void (^)(void))block
5977

6078
- (void)viewWillAppear:(BOOL)animated
6179
{
62-
[super viewWillAppear:animated];
80+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
81+
[UIView animateWithDuration:0.4 animations:^{
82+
_backgroundView.alpha = 0.4;
83+
84+
CGRect frame = _activityView.frame;
85+
frame.origin.y = self.view.frame.size.height - self.height;
86+
_activityView.frame = frame;
87+
}];
88+
}
6389

64-
[UIView animateWithDuration:0.4 animations:^{
65-
_backgroundView.alpha = 0.4;
66-
CGRect frame = _activityView.frame;
67-
frame.origin.y = [UIScreen mainScreen].bounds.size.height - self.height;
68-
_activityView.frame = frame;
69-
}];
90+
[super viewWillAppear:animated];
7091
}
7192

72-
- (NSInteger)height
93+
- (void)viewWillDisappear:(BOOL)animated
7394
{
74-
return 437;
95+
[super viewWillDisappear: animated];
96+
}
97+
98+
- (NSInteger)height
99+
{
100+
if (_activities.count <= 3) return 204;
101+
if (_activities.count <= 6) return 304;
102+
return 417;
75103
}
76104

77105
- (void)viewDidLoad

‎REActivityViewController/RETwitterActivity.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ - (id)init
1717
self = [super initWithTitle:@"Twitter"
1818
image:[UIImage imageNamed:@"Icon_Twitter"]
1919
actionBlock:^(REActivity *activity, REActivityViewController *activityViewController) {
20-
UIViewController *presenter = activityViewController.presentingViewController;
20+
UIViewController *presenter = activityViewController.presentingController;
2121
NSDictionary *userInfo = activityViewController.userInfo;
2222

2323
[activityViewController dismissViewControllerAnimated:YES completion:^{

‎REActivityViewControllerExample/REActivityViewControllerExample.xcodeproj/project.pbxproj‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
309664BC16B1E8CF00440203 /* Icon_Twitter@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 309664B516B1E8CF00440203 /* Icon_Twitter@2x.png */; };
3434
309664BF16B1EC8200440203 /* Temp@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 309664BE16B1EC8200440203 /* Temp@2x.png */; };
3535
309664C116B1F02900440203 /* Button@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 309664C016B1F02900440203 /* Button@2x.png */; };
36-
309664C316B1F40000440203 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 309664C216B1F40000440203 /* Social.framework */; };
36+
309664C316B1F40000440203 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 309664C216B1F40000440203 /* Social.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
3737
309664C516B1F40400440203 /* Twitter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 309664C416B1F40400440203 /* Twitter.framework */; };
38+
30A8392416B2251C00E9482B /* RootViewController_iPad.m in Sources */ = {isa = PBXBuildFile; fileRef = 30A8392316B2251C00E9482B /* RootViewController_iPad.m */; };
3839
/* End PBXBuildFile section */
3940

4041
/* Begin PBXFileReference section */
@@ -78,6 +79,8 @@
7879
309664C016B1F02900440203 /* Button@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Button@2x.png"; sourceTree = "<group>"; };
7980
309664C216B1F40000440203 /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; };
8081
309664C416B1F40400440203 /* Twitter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Twitter.framework; path = System/Library/Frameworks/Twitter.framework; sourceTree = SDKROOT; };
82+
30A8392216B2251C00E9482B /* RootViewController_iPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController_iPad.h; sourceTree = "<group>"; };
83+
30A8392316B2251C00E9482B /* RootViewController_iPad.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController_iPad.m; sourceTree = "<group>"; };
8184
/* End PBXFileReference section */
8285

8386
/* Begin PBXFrameworksBuildPhase section */
@@ -134,6 +137,8 @@
134137
3096648116B1B36B00440203 /* AppDelegate.m */,
135138
3096649216B1B3D900440203 /* RootViewController.h */,
136139
3096649316B1B3D900440203 /* RootViewController.m */,
140+
30A8392216B2251C00E9482B /* RootViewController_iPad.h */,
141+
30A8392316B2251C00E9482B /* RootViewController_iPad.m */,
137142
3096647816B1B36B00440203 /* Supporting Files */,
138143
);
139144
path = REActivityViewControllerExample;
@@ -283,6 +288,7 @@
283288
309664A016B1B95500440203 /* REMessageActivity.m in Sources */,
284289
309664A316B1B96A00440203 /* REMailActivity.m in Sources */,
285290
309664A916B1D62300440203 /* REActivityView.m in Sources */,
291+
30A8392416B2251C00E9482B /* RootViewController_iPad.m in Sources */,
286292
);
287293
runOnlyForDeploymentPostprocessing = 0;
288294
};
@@ -358,6 +364,7 @@
358364
INFOPLIST_FILE = "REActivityViewControllerExample/REActivityViewControllerExample-Info.plist";
359365
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
360366
PRODUCT_NAME = "$(TARGET_NAME)";
367+
TARGETED_DEVICE_FAMILY = "1,2";
361368
WRAPPER_EXTENSION = app;
362369
};
363370
name = Debug;
@@ -370,6 +377,7 @@
370377
INFOPLIST_FILE = "REActivityViewControllerExample/REActivityViewControllerExample-Info.plist";
371378
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
372379
PRODUCT_NAME = "$(TARGET_NAME)";
380+
TARGETED_DEVICE_FAMILY = "1,2";
373381
WRAPPER_EXTENSION = app;
374382
};
375383
name = Release;
@@ -393,6 +401,7 @@
393401
3096648D16B1B36B00440203 /* Release */,
394402
);
395403
defaultConfigurationIsVisible = 0;
404+
defaultConfigurationName = Release;
396405
};
397406
/* End XCConfigurationList section */
398407
};

‎REActivityViewControllerExample/REActivityViewControllerExample/AppDelegate.m‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
#import "AppDelegate.h"
1010
#import "RootViewController.h"
11+
#import "RootViewController_iPad.h"
1112

1213
@implementation AppDelegate
1314

1415
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1516
{
1617
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
1718

18-
self.window.rootViewController = [[RootViewController alloc] init];
19+
self.window.rootViewController = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? [[RootViewController alloc] init] : [[UINavigationController alloc] initWithRootViewController:[[RootViewController_iPad alloc] init]];
1920
self.window.backgroundColor = [UIColor whiteColor];
2021
[self.window makeKeyAndVisible];
2122
return YES;

‎REActivityViewControllerExample/REActivityViewControllerExample/RootViewController.m‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,21 @@ - (void)buttonPressed
6969
//
7070
//NSArray *activities = @[facebookActivity, twitterActivity, messageActivity, mailActivity, customActivity];
7171

72-
NSArray *activities = @[facebookActivity, twitterActivity, messageActivity, mailActivity1, mailActivity2, mailActivity3, mailActivity4, mailActivity5, mailActivity6, mailActivity7, mailActivity8, mailActivity9, mailActivity10, mailActivity2, mailActivity3, mailActivity4, mailActivity5, mailActivity6, mailActivity7, mailActivity8, mailActivity9, mailActivity10];
72+
NSArray *activities = @[facebookActivity, twitterActivity, messageActivity, mailActivity1, mailActivity1, mailActivity1, mailActivity1, mailActivity1, mailActivity1, mailActivity1];
7373

7474
//self.presentingViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
7575
//self.modalPresentationStyle = UIModalPresentationCurrentContext;
7676
// Create REActivityViewController controller and assign data source
7777
//
78-
REActivityViewController *activityViewController = [[REActivityViewController alloc] initWithActivities:activities];
78+
REActivityViewController *activityViewController = [[REActivityViewController alloc] initWithViewController:self activities:activities];
7979
activityViewController.userInfo = @{
8080
@"image": [UIImage imageNamed:@"Temp@2x.png"],
8181
@"text": @"Hello world!",
8282
@"url": [NSURL URLWithString:@"https://github.com/romaonthego/REActivityViewController"]
8383
};
8484
self.modalPresentationStyle = UIModalPresentationCurrentContext;
8585
[self presentViewController:activityViewController animated:YES completion:^{
86-
// self.modalPresentationStyle = UIModalPresentationFullScreen;
86+
self.modalPresentationStyle = UIModalPresentationFullScreen;
8787
}];
8888
}
8989

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// RootViewController_iPad.h
3+
// REActivityViewControllerExample
4+
//
5+
// Created by Roman Efimov on 1/24/13.
6+
// Copyright (c) 2013 Roman Efimov. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface RootViewController_iPad : UIViewController {
12+
UIPopoverController *_activityPopoverController;
13+
}
14+
15+
@end

0 commit comments

Comments
 (0)