ViewController.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. //
  2. // ViewController.m
  3. //
  4. // Copyright (c) 2013-2017 Evgeny Aleksandrov. License: MIT.
  5. #import <EAIntroView/EAIntroView.h>
  6. #import <SMPageControl/SMPageControl.h>
  7. #import "ViewController.h"
  8. static NSString * const sampleDescription1 = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
  9. static NSString * const sampleDescription2 = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore.";
  10. static NSString * const sampleDescription3 = @"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.";
  11. static NSString * const sampleDescription4 = @"Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit.";
  12. @interface ViewController () <EAIntroDelegate> {
  13. UIView *rootView;
  14. EAIntroView *_intro;
  15. }
  16. @end
  17. @implementation ViewController
  18. #pragma mark - View lifecycle
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // using self.navigationController.view - to display EAIntroView above navigation bar
  22. rootView = self.navigationController.view;
  23. }
  24. #pragma mark - Demo
  25. - (void)showIntroWithCrossDissolve {
  26. EAIntroPage *page1 = [EAIntroPage page];
  27. page1.title = @"Hello world";
  28. page1.desc = sampleDescription1;
  29. page1.bgImage = [UIImage imageNamed:@"bg1"];
  30. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  31. EAIntroPage *page2 = [EAIntroPage page];
  32. page2.title = @"This is page 2";
  33. page2.desc = sampleDescription2;
  34. page2.bgImage = [UIImage imageNamed:@"bg2"];
  35. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
  36. EAIntroPage *page3 = [EAIntroPage page];
  37. page3.title = @"This is page 3";
  38. page3.desc = sampleDescription3;
  39. page3.bgImage = [UIImage imageNamed:@"bg3"];
  40. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
  41. EAIntroPage *page4 = [EAIntroPage page];
  42. page4.title = @"This is page 4";
  43. page4.desc = sampleDescription4;
  44. page4.bgImage = [UIImage imageNamed:@"bg4"];
  45. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
  46. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  47. intro.skipButtonAlignment = EAViewAlignmentCenter;
  48. intro.skipButtonY = 80.f;
  49. intro.pageControlY = 42.f;
  50. [intro setDelegate:self];
  51. [intro showInView:rootView animateDuration:0.3];
  52. }
  53. - (void)showIntroWithFixedTitleView {
  54. EAIntroPage *page1 = [EAIntroPage page];
  55. page1.title = @"Hello world";
  56. page1.desc = sampleDescription1;
  57. EAIntroPage *page2 = [EAIntroPage page];
  58. page2.title = @"This is page 2";
  59. page2.desc = sampleDescription2;
  60. EAIntroPage *page3 = [EAIntroPage page];
  61. page3.title = @"This is page 3";
  62. page3.desc = sampleDescription3;
  63. EAIntroPage *page4 = [EAIntroPage page];
  64. page4.title = @"This is page 4";
  65. page4.desc = sampleDescription4;
  66. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  67. [intro setDelegate:self];
  68. UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  69. intro.titleView = titleView;
  70. intro.titleViewY = 90;
  71. intro.backgroundColor = [UIColor colorWithRed:0.f green:0.49f blue:0.96f alpha:1.f]; //iOS7 dark blue
  72. [intro showInView:rootView animateDuration:0.3];
  73. }
  74. - (void)showIntroWithCustomPages {
  75. EAIntroPage *page1 = [EAIntroPage page];
  76. page1.title = @"Hello world";
  77. page1.desc = sampleDescription1;
  78. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  79. EAIntroPage *page2 = [EAIntroPage page];
  80. page2.title = @"This is page 2";
  81. page2.titlePositionY = self.view.bounds.size.height/2 - 10;
  82. page2.desc = sampleDescription2;
  83. page2.descPositionY = self.view.bounds.size.height/2 - 50;
  84. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
  85. page2.titleIconPositionY = 70;
  86. EAIntroPage *page3 = [EAIntroPage page];
  87. page3.title = @"This is page 3";
  88. page3.titleFont = [UIFont fontWithName:@"Georgia-BoldItalic" size:20];
  89. page3.titlePositionY = 220;
  90. page3.desc = sampleDescription2;
  91. page3.descFont = [UIFont fontWithName:@"Georgia-Italic" size:18];
  92. page3.descPositionY = 200;
  93. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
  94. page3.titleIconPositionY = 100;
  95. EAIntroPage *page4 = [EAIntroPage page];
  96. page4.title = @"This is page 4";
  97. page4.desc = sampleDescription4;
  98. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
  99. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  100. intro.bgImage = [UIImage imageNamed:@"bg2"];
  101. intro.pageControlY = 250.f;
  102. UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  103. [btn setFrame:CGRectMake(0, 0, 230, 40)];
  104. [btn setTitle:@"SKIP NOW" forState:UIControlStateNormal];
  105. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  106. btn.layer.borderWidth = 2.f;
  107. btn.layer.cornerRadius = 10;
  108. btn.layer.borderColor = [[UIColor whiteColor] CGColor];
  109. intro.skipButton = btn;
  110. intro.skipButtonY = 60.f;
  111. intro.skipButtonAlignment = EAViewAlignmentCenter;
  112. [intro setDelegate:self];
  113. [intro showInView:rootView animateDuration:0.3];
  114. }
  115. - (void)showIntroWithCustomView {
  116. EAIntroPage *page1 = [EAIntroPage page];
  117. page1.title = @"Hello world";
  118. page1.desc = sampleDescription1;
  119. page1.bgImage = [UIImage imageNamed:@"bg1"];
  120. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  121. UIView *viewForPage2 = [[UIView alloc] initWithFrame:rootView.bounds];
  122. UILabel *labelForPage2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, rootView.bounds.size.width, 30)];
  123. labelForPage2.text = @"Some custom view";
  124. labelForPage2.font = [UIFont systemFontOfSize:32];
  125. labelForPage2.textColor = [UIColor whiteColor];
  126. labelForPage2.backgroundColor = [UIColor clearColor];
  127. labelForPage2.transform = CGAffineTransformMakeRotation(M_PI_2*3);
  128. [viewForPage2 addSubview:labelForPage2];
  129. EAIntroPage *page2 = [EAIntroPage pageWithCustomView:viewForPage2];
  130. page2.bgImage = [UIImage imageNamed:@"bg2"];
  131. EAIntroPage *page3 = [EAIntroPage page];
  132. page3.title = @"This is page 3";
  133. page3.desc = sampleDescription3;
  134. page3.bgImage = [UIImage imageNamed:@"bg3"];
  135. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
  136. EAIntroPage *page4 = [EAIntroPage page];
  137. page4.title = @"This is page 4";
  138. page4.desc = sampleDescription4;
  139. page4.bgImage = [UIImage imageNamed:@"bg4"];
  140. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
  141. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  142. [intro.skipButton setTitle:@"Skip now" forState:UIControlStateNormal];
  143. [intro setDelegate:self];
  144. intro.tapToNext = YES;
  145. [intro showInView:rootView animateDuration:0.3];
  146. }
  147. - (void)showIntroWithCustomViewFromNib {
  148. EAIntroPage *page1 = [EAIntroPage page];
  149. page1.title = @"Hello world";
  150. page1.desc = sampleDescription1;
  151. page1.bgImage = [UIImage imageNamed:@"bg1"];
  152. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  153. EAIntroPage *page2 = [EAIntroPage pageWithCustomViewFromNibNamed:@"IntroPage"];
  154. page2.bgImage = [UIImage imageNamed:@"bg2"];
  155. EAIntroPage *page3 = [EAIntroPage page];
  156. page3.title = @"This is page 3";
  157. page3.desc = sampleDescription3;
  158. page3.bgImage = [UIImage imageNamed:@"bg3"];
  159. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
  160. EAIntroPage *page4 = [EAIntroPage page];
  161. page4.title = @"This is page 4";
  162. page4.desc = sampleDescription4;
  163. page4.bgImage = [UIImage imageNamed:@"bg4"];
  164. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
  165. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  166. [intro setDelegate:self];
  167. UISwitch *switchControl = (UISwitch *)[page2.pageView viewWithTag:1];
  168. if(switchControl) {
  169. [switchControl addTarget:self action:@selector(switchFlip:) forControlEvents:UIControlEventValueChanged];
  170. }
  171. [intro showInView:rootView animateDuration:0.3];
  172. _intro = intro;
  173. }
  174. - (void)showIntroWithSeparatePagesInitAndPageCallback {
  175. EAIntroPage *page1 = [EAIntroPage page];
  176. page1.title = @"Hello world";
  177. page1.desc = sampleDescription1;
  178. page1.bgImage = [UIImage imageNamed:@"bg1"];
  179. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  180. EAIntroPage *page2 = [EAIntroPage page];
  181. page2.title = @"This is page 2";
  182. page2.desc = sampleDescription2;
  183. page2.bgImage = [UIImage imageNamed:@"bg2"];
  184. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title2"]];
  185. page2.onPageDidAppear = ^{
  186. NSLog(@"Page 2 did appear block");
  187. };
  188. EAIntroPage *page3 = [EAIntroPage page];
  189. page3.title = @"This is page 3";
  190. page3.desc = sampleDescription3;
  191. page3.bgImage = [UIImage imageNamed:@"bg3"];
  192. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title3"]];
  193. EAIntroPage *page4 = [EAIntroPage page];
  194. page4.title = @"This is page 4";
  195. page4.desc = sampleDescription4;
  196. page4.bgImage = [UIImage imageNamed:@"bg4"];
  197. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title4"]];
  198. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds];
  199. [intro setDelegate:self];
  200. // show skipButton only on 3rd page + animation
  201. intro.skipButton.alpha = 0.f;
  202. intro.skipButton.enabled = NO;
  203. page3.onPageDidAppear = ^{
  204. intro.skipButton.enabled = YES;
  205. [UIView animateWithDuration:0.3f animations:^{
  206. intro.skipButton.alpha = 1.f;
  207. }];
  208. };
  209. page3.onPageDidDisappear = ^{
  210. intro.skipButton.enabled = NO;
  211. [UIView animateWithDuration:0.3f animations:^{
  212. intro.skipButton.alpha = 0.f;
  213. }];
  214. };
  215. [intro setPages:@[page1,page2,page3,page4]];
  216. [intro showInView:rootView animateDuration:0.3];
  217. }
  218. - (void)showCustomIntro {
  219. EAIntroPage *page1 = [EAIntroPage page];
  220. page1.title = @"Hello world";
  221. page1.titlePositionY = 240;
  222. page1.desc = sampleDescription1;
  223. page1.descPositionY = 220;
  224. page1.bgImage = [UIImage imageNamed:@"bg1"];
  225. page1.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title1"]];
  226. page1.titleIconPositionY = 100;
  227. page1.showTitleView = NO;
  228. EAIntroPage *page2 = [EAIntroPage page];
  229. page2.title = @"This is page 2";
  230. page2.titlePositionY = 240;
  231. page2.desc = sampleDescription2;
  232. page2.descPositionY = 220;
  233. page2.bgImage = [UIImage imageNamed:@"bg2"];
  234. page2.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon1"]];
  235. page2.titleIconPositionY = 260;
  236. EAIntroPage *page3 = [EAIntroPage page];
  237. page3.title = @"This is page 3";
  238. page3.titlePositionY = 240;
  239. page3.desc = sampleDescription3;
  240. page3.descPositionY = 220;
  241. page3.bgImage = [UIImage imageNamed:@"bg3"];
  242. page3.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon2"]];
  243. page3.titleIconPositionY = 260;
  244. EAIntroPage *page4 = [EAIntroPage page];
  245. page4.title = @"This is page 4";
  246. page4.titlePositionY = 240;
  247. page4.desc = sampleDescription4;
  248. page4.descPositionY = 220;
  249. page4.bgImage = [UIImage imageNamed:@"bg4"];
  250. page4.titleIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon3"]];
  251. page4.titleIconPositionY = 260;
  252. EAIntroView *intro = [[EAIntroView alloc] initWithFrame:rootView.bounds andPages:@[page1,page2,page3,page4]];
  253. intro.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bigLogo"]];
  254. intro.titleViewY = 120;
  255. intro.tapToNext = YES;
  256. [intro setDelegate:self];
  257. SMPageControl *pageControl = [[SMPageControl alloc] init];
  258. pageControl.pageIndicatorImage = [UIImage imageNamed:@"pageDot"];
  259. pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"selectedPageDot"];
  260. [pageControl sizeToFit];
  261. // This is a hack - not recommended for Swift, more information: https://github.com/ealeksandrov/EAIntroView/issues/161
  262. intro.pageControl = (UIPageControl *)pageControl;
  263. intro.pageControlY = 130.f;
  264. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  265. [btn setBackgroundImage:[UIImage imageNamed:@"skipButton"] forState:UIControlStateNormal];
  266. [btn setFrame:CGRectMake(0, 0, 270, 50)];
  267. intro.skipButton = btn;
  268. intro.skipButtonY = 80.f;
  269. intro.skipButtonAlignment = EAViewAlignmentCenter;
  270. [intro showInView:rootView animateDuration:0.3];
  271. }
  272. #pragma mark - EAIntroView delegate
  273. - (void)introDidFinish:(EAIntroView *)introView wasSkipped:(BOOL)wasSkipped {
  274. if(wasSkipped) {
  275. NSLog(@"Intro skipped");
  276. } else {
  277. NSLog(@"Intro finished");
  278. }
  279. }
  280. #pragma mark - Custom actions
  281. - (IBAction)switchFlip:(id)sender {
  282. UISwitch *switchControl = (UISwitch *) sender;
  283. NSLog(@"%@", switchControl.on ? @"On" : @"Off");
  284. // limit scrolling on one, currently visible page (can't go previous or next page)
  285. //[_intro setScrollingEnabled:switchControl.on];
  286. if(!switchControl.on) {
  287. // scroll no further selected page (can go previous pages, but not next)
  288. _intro.limitPageIndex = _intro.visiblePageIndex;
  289. } else {
  290. [_intro setScrollingEnabled:YES];
  291. }
  292. }
  293. #pragma mark - UITableView delegate
  294. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  295. if (indexPath.row == 0) {
  296. // all settings are basic, pages with custom packgrounds, title image on each page
  297. [self showIntroWithCrossDissolve];
  298. } else if (indexPath.row == 1) {
  299. // all settings are basic, introview with colored background, fixed title image
  300. [self showIntroWithFixedTitleView];
  301. } else if (indexPath.row == 2) {
  302. // basic pages with custom settings
  303. [self showIntroWithCustomPages];
  304. } else if (indexPath.row == 3) {
  305. // using page with custom view
  306. [self showIntroWithCustomView];
  307. } else if (indexPath.row == 4) {
  308. // using page with custom view from nib
  309. [self showIntroWithCustomViewFromNib];
  310. } else if (indexPath.row == 5) {
  311. // pages separate init and using block callback in one of pages
  312. [self showIntroWithSeparatePagesInitAndPageCallback];
  313. } else if (indexPath.row == 6) {
  314. // show custom intro
  315. [self showCustomIntro];
  316. }
  317. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  318. }
  319. @end