Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4.  
  5. screenBounds = [[UIScreen mainScreen] bounds];
  6.  
  7. scrollTitle = [[NSMutableArray alloc]initWithObjects:@"Alerts",@"Profile",@"Help",nil];
  8. tabBarArray = [[NSMutableArray alloc]initWithObjects:@"Alerts",@"Profile",@"Help",nil];
  9.  
  10. // Do any additional setup after loading the view from its nib.
  11. currentPage = 0;
  12.  
  13. segmentedControll = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"Alerts",@"Profile",@"Help"]];
  14. segmentedControll.backgroundColor = [UIColor colorWithRed:227/255.0 green:230/255.0 blue:230/255.0 alpha:1.0];
  15. [segmentedControll setFrame:CGRectMake(0, 46, 320, 40)];
  16. [segmentedControll setSelectedSegmentIndex:1];
  17. containerView = [[HMSegmentedControlContainerView alloc] initWithHMSegmentedControl:segmentedControll andMinimumWIdth:107];
  18.  
  19. containerView.scrollView.showsHorizontalScrollIndicator=0;
  20.  
  21. __weak typeof(self) weakSelf = self;
  22. [segmentedControll setIndexChangeBlock:^(NSInteger index) {
  23. [weakSelf.menuScrollView scrollRectToVisible:CGRectMake(320 * index, 0, 320, 200) animated:YES];
  24. }];
  25.  
  26. [self.view addSubview:containerView];
  27. totalNoOfSegment=3;
  28. currentPage=segmentedControll.selectedSegmentIndex;
  29.  
  30. self.menuScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 87, 320, 373)];
  31. [self.menuScrollView setBackgroundColor:[UIColor colorWithRed:0.7 green:0.7 blue:0.7 alpha:1]];
  32. [self.menuScrollView setPagingEnabled:YES];
  33. [self.menuScrollView setShowsHorizontalScrollIndicator:NO];
  34. [self.menuScrollView setContentSize:CGSizeMake(960, 200)];
  35. [self.menuScrollView scrollRectToVisible:CGRectMake(320, 0, 320, 200) animated:NO];
  36. [self.menuScrollView setDelegate:self];
  37. [self.view addSubview:self.menuScrollView];
  38.  
  39. UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 373)];
  40. [label1 setText:@"Alerts"];
  41. label1.textColor = [UIColor blackColor];
  42. label1.backgroundColor = [UIColor whiteColor];
  43. label1.textAlignment = NSTextAlignmentCenter;
  44. [self.menuScrollView addSubview:label1];
  45.  
  46. UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(320, 0, 320, 373)];
  47. [label2 setText:@"Profile"];
  48. label2.textColor = [UIColor blackColor];
  49. label2.backgroundColor = [UIColor whiteColor];
  50. label2.textAlignment = NSTextAlignmentCenter;
  51. [self.menuScrollView addSubview:label2];
  52.  
  53. UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(640, 0, 320, 373)];
  54. [label3 setText:@"Help"];
  55. label3.textColor = [UIColor blackColor];
  56. label3.backgroundColor = [UIColor whiteColor];
  57. label3.textAlignment = NSTextAlignmentCenter;
  58. [self.menuScrollView addSubview:label3];
  59.  
  60.  
  61. self.panGestureLeft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(panTableView:)];
  62. self.panGestureLeft.direction=UISwipeGestureRecognizerDirectionLeft ;
  63. [self.menuScrollView addGestureRecognizer:self.panGestureLeft];
  64. self.panGestureRight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(panTableView:)];
  65. self.panGestureRight.direction=UISwipeGestureRecognizerDirectionRight ;
  66. [self.menuScrollView addGestureRecognizer:self.panGestureRight];
  67. }
  68.  
  69. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView1 {
  70. CGFloat pageWidth = self.menuScrollView.frame.size.width;
  71. NSInteger page = self.menuScrollView.contentOffset.x / pageWidth;
  72.  
  73. [segmentedControll setSelectedSegmentIndex:page animated:YES];
  74. }
  75.  
  76. -(void)panTableView:(UISwipeGestureRecognizer *)pan{
  77. if (pan.state==UIGestureRecognizerStateEnded) {
  78. int curr=currentPage;
  79.  
  80. if (pan==self.panGestureLeft)
  81. {
  82. // user dragged towards the right
  83. curr=curr+1;
  84. if (curr!=3) {
  85. CATransition *transition = [CATransition animation];
  86. transition.duration = 0.35;
  87. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  88. transition.type = kCATransitionPush;
  89. transition.subtype =kCATransitionFromRight;
  90. transition.delegate = self;
  91. [self.menuScrollView.layer addAnimation:transition forKey:nil];
  92. segmentedControll.selectedSegmentIndex=curr;
  93. [self segmentedControlChangedValue:segmentedControll];
  94. }
  95.  
  96. }
  97. else if (pan==self.panGestureRight)
  98.  
  99. {
  100. // user dragged towards the left
  101. curr=curr-1;
  102. if (curr!=-1) {
  103. CATransition *transition = [CATransition animation];
  104. transition.duration = 0.35;
  105. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  106. transition.type = kCATransitionPush;
  107. transition.subtype =kCATransitionFromLeft;
  108. transition.delegate = self;
  109. [self.menuScrollView.layer addAnimation:transition forKey:nil];
  110. segmentedControll.selectedSegmentIndex=curr;
  111. [self segmentedControlChangedValue:segmentedControll];
  112.  
  113. }
  114. }
  115. }
  116. }
  117.  
  118. - (void)segmentedControlChangedValue:(HMSegmentedControl *)segmentedControl {
  119. NSLog(@"Selected index %i (via UIControlEventValueChanged)", segmentedControl.selectedSegmentIndex);
  120. currentPage=segmentedControl.selectedSegmentIndex;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement