mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Structure project almost by features. Start by organizing view controllers.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import <MatrixSDK/MatrixSDK.h>
|
||||
|
||||
#import "UIViewController+RiotSearch.h"
|
||||
|
||||
/**
|
||||
This view controller manages several uiviewcontrollers like UISegmentedController manages uiTableView
|
||||
except that the managed items are custom UIViewControllers.
|
||||
It uses a Vector design.
|
||||
*/
|
||||
@interface SegmentedViewController : MXKViewController
|
||||
|
||||
#pragma mark - Class methods
|
||||
@property (weak, nonatomic) IBOutlet UIView *selectionContainer;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectionContainerTopConstraint;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectionContainerHeightConstraint;
|
||||
@property (weak, nonatomic) IBOutlet UIView *viewControllerContainer;
|
||||
|
||||
/**
|
||||
The index of the view controller that currently has the focus.
|
||||
*/
|
||||
@property (nonatomic) NSUInteger selectedIndex;
|
||||
|
||||
/**
|
||||
The tint color for the section header (kRiotColorGreen by default).
|
||||
*/
|
||||
@property (nonatomic) UIColor *sectionHeaderTintColor;
|
||||
|
||||
/**
|
||||
The view controller that currently has the focus.
|
||||
*/
|
||||
@property (nonatomic, readonly) UIViewController *selectedViewController;
|
||||
|
||||
/**
|
||||
The view controllers managed by this SegmentedViewController instance.
|
||||
*/
|
||||
@property (nonatomic, readonly) NSArray<UIViewController*> *viewControllers;
|
||||
|
||||
/**
|
||||
Returns the `UINib` object initialized for a `SegmentedViewController`.
|
||||
|
||||
@return The initialized `UINib` object or `nil` if there were errors during initialization
|
||||
or the nib file could not be located.
|
||||
|
||||
@discussion You may override this method to provide a customized nib. If you do,
|
||||
you should also override `SegmentedViewController` to return your
|
||||
view controller loaded from your custom nib.
|
||||
*/
|
||||
+ (UINib *)nib;
|
||||
|
||||
/**
|
||||
Creates and returns a new `SegmentedViewController` object.
|
||||
|
||||
@discussion This is the designated initializer for programmatic instantiation.
|
||||
@return An initialized `SegmentedViewController` object if successful, `nil` otherwise.
|
||||
*/
|
||||
+ (instancetype)segmentedViewController;
|
||||
|
||||
/**
|
||||
init the segmentedViewController with a list of UIViewControllers.
|
||||
The subviewcontrollers must implement didMoveToParentViewController to display the navbar button.
|
||||
|
||||
@discussion: the segmentedViewController gets the ownership of the provided arrays and their content.
|
||||
|
||||
@param titles the section tiles
|
||||
@param viewControllers the list of viewControllers to display.
|
||||
@param defaultSelected index of the default selected UIViewController in the list.
|
||||
*/
|
||||
- (void)initWithTitles:(NSArray*)titles viewControllers:(NSArray*)viewControllers defaultSelected:(NSUInteger)defaultSelected;
|
||||
|
||||
/**
|
||||
Callback used to take into account the change of the user interface theme.
|
||||
*/
|
||||
- (void)userInterfaceThemeDidChange;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,546 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#import "SegmentedViewController.h"
|
||||
|
||||
#import "RiotDesignValues.h"
|
||||
|
||||
@interface SegmentedViewController ()
|
||||
{
|
||||
// Tell whether the segmented view is appeared (see viewWillAppear/viewWillDisappear).
|
||||
BOOL isViewAppeared;
|
||||
|
||||
// list of displayed UIViewControllers
|
||||
NSArray* viewControllers;
|
||||
|
||||
// The constraints of the displayed viewController
|
||||
NSLayoutConstraint *displayedVCTopConstraint;
|
||||
NSLayoutConstraint *displayedVCLeftConstraint;
|
||||
NSLayoutConstraint *displayedVCWidthConstraint;
|
||||
NSLayoutConstraint *displayedVCHeightConstraint;
|
||||
|
||||
// list of NSString
|
||||
NSArray* sectionTitles;
|
||||
|
||||
// list of section labels
|
||||
NSArray* sectionLabels;
|
||||
|
||||
// the selected marker view
|
||||
UIView* selectedMarkerView;
|
||||
NSLayoutConstraint *leftMarkerViewConstraint;
|
||||
|
||||
// Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change.
|
||||
id kRiotDesignValuesDidChangeThemeNotificationObserver;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SegmentedViewController
|
||||
|
||||
#pragma mark - Class methods
|
||||
|
||||
+ (UINib *)nib
|
||||
{
|
||||
return [UINib nibWithNibName:NSStringFromClass([SegmentedViewController class])
|
||||
bundle:[NSBundle bundleForClass:[SegmentedViewController class]]];
|
||||
}
|
||||
|
||||
+ (instancetype)segmentedViewController
|
||||
{
|
||||
return [[[self class] alloc] initWithNibName:NSStringFromClass([SegmentedViewController class])
|
||||
bundle:[NSBundle bundleForClass:[SegmentedViewController class]]];
|
||||
}
|
||||
|
||||
/**
|
||||
init the segmentedViewController with a list of UIViewControllers.
|
||||
@param titles the section tiles
|
||||
@param viewControllers the list of viewControllers to display.
|
||||
@param defaultSelected index of the default selected UIViewController in the list.
|
||||
*/
|
||||
- (void)initWithTitles:(NSArray*)titles viewControllers:(NSArray*)someViewControllers defaultSelected:(NSUInteger)defaultSelected
|
||||
{
|
||||
viewControllers = someViewControllers;
|
||||
sectionTitles = titles;
|
||||
_selectedIndex = defaultSelected;
|
||||
}
|
||||
|
||||
- (void)destroy
|
||||
{
|
||||
for (id viewController in viewControllers)
|
||||
{
|
||||
if ([viewController respondsToSelector:@selector(destroy)])
|
||||
{
|
||||
[viewController destroy];
|
||||
}
|
||||
}
|
||||
viewControllers = nil;
|
||||
sectionTitles = nil;
|
||||
|
||||
sectionLabels = nil;
|
||||
|
||||
if (selectedMarkerView)
|
||||
{
|
||||
[selectedMarkerView removeFromSuperview];
|
||||
selectedMarkerView = nil;
|
||||
}
|
||||
|
||||
if (kRiotDesignValuesDidChangeThemeNotificationObserver)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver];
|
||||
kRiotDesignValuesDidChangeThemeNotificationObserver = nil;
|
||||
}
|
||||
|
||||
[super destroy];
|
||||
}
|
||||
|
||||
- (void)setSelectedIndex:(NSUInteger)selectedIndex
|
||||
{
|
||||
if (_selectedIndex != selectedIndex)
|
||||
{
|
||||
_selectedIndex = selectedIndex;
|
||||
[self displaySelectedViewController];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray<UIViewController *> *)viewControllers
|
||||
{
|
||||
return viewControllers;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)finalizeInit
|
||||
{
|
||||
[super finalizeInit];
|
||||
|
||||
// Setup `MXKViewControllerHandling` properties
|
||||
self.enableBarTintColorStatusChange = NO;
|
||||
|
||||
self.sectionHeaderTintColor = kRiotColorGreen;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
// Check whether the view controller has been pushed via storyboard
|
||||
if (!self.viewControllerContainer)
|
||||
{
|
||||
// Instantiate view controller objects
|
||||
[[[self class] nib] instantiateWithOwner:self options:nil];
|
||||
}
|
||||
|
||||
// Adjust Top
|
||||
[NSLayoutConstraint deactivateConstraints:@[self.selectionContainerTopConstraint]];
|
||||
|
||||
// it is not possible to define a constraint to the topLayoutGuide in the xib editor
|
||||
// so do it in the code ..
|
||||
self.selectionContainerTopConstraint = [NSLayoutConstraint constraintWithItem:self.topLayoutGuide
|
||||
attribute:NSLayoutAttributeBottom
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1.0f
|
||||
constant:0.0f];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:@[self.selectionContainerTopConstraint]];
|
||||
|
||||
[self createSegmentedViews];
|
||||
|
||||
// Observe user interface theme change.
|
||||
kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
||||
|
||||
[self userInterfaceThemeDidChange];
|
||||
|
||||
}];
|
||||
[self userInterfaceThemeDidChange];
|
||||
}
|
||||
|
||||
- (void)userInterfaceThemeDidChange
|
||||
{
|
||||
self.defaultBarTintColor = kRiotSecondaryBgColor;
|
||||
self.barTitleColor = kRiotPrimaryTextColor;
|
||||
self.activityIndicator.backgroundColor = kRiotOverlayColor;
|
||||
|
||||
self.view.backgroundColor = kRiotPrimaryBgColor;
|
||||
}
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||
{
|
||||
return kRiotDesignStatusBarStyle;
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
if (_selectedViewController)
|
||||
{
|
||||
// Make iOS invoke child viewWillAppear
|
||||
[_selectedViewController beginAppearanceTransition:YES animated:animated];
|
||||
}
|
||||
|
||||
isViewAppeared = YES;
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
if (_selectedViewController)
|
||||
{
|
||||
// Make iOS invoke child viewWillDisappear
|
||||
[_selectedViewController beginAppearanceTransition:NO animated:animated];
|
||||
}
|
||||
|
||||
isViewAppeared = NO;
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated
|
||||
{
|
||||
[super viewDidAppear:animated];
|
||||
|
||||
if (_selectedViewController)
|
||||
{
|
||||
// Make iOS invoke child viewDidAppear
|
||||
[_selectedViewController endAppearanceTransition];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
[super viewDidDisappear:animated];
|
||||
|
||||
if (_selectedViewController)
|
||||
{
|
||||
// Make iOS invoke child viewDidDisappear
|
||||
[_selectedViewController endAppearanceTransition];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createSegmentedViews
|
||||
{
|
||||
NSMutableArray* labels = [[NSMutableArray alloc] init];
|
||||
|
||||
NSUInteger count = viewControllers.count;
|
||||
|
||||
for (NSUInteger index = 0; index < count; index++)
|
||||
{
|
||||
// create programmatically each label
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
|
||||
label.text = [sectionTitles objectAtIndex:index];
|
||||
label.font = [UIFont systemFontOfSize:17];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.textColor = _sectionHeaderTintColor;
|
||||
label.backgroundColor = [UIColor clearColor];
|
||||
label.accessibilityIdentifier = [NSString stringWithFormat:@"SegmentedVCSectionLabel%tu", index];
|
||||
|
||||
// the constraint defines the label frame
|
||||
// so ignore any autolayout stuff
|
||||
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
// add the label before setting the constraints
|
||||
[self.selectionContainer addSubview:label];
|
||||
|
||||
NSLayoutConstraint *leftConstraint;
|
||||
if (labels.count)
|
||||
{
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:label
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:[labels objectAtIndex:(index-1)]
|
||||
attribute:NSLayoutAttributeTrailing
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
}
|
||||
else
|
||||
{
|
||||
leftConstraint = [NSLayoutConstraint constraintWithItem:label
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
}
|
||||
|
||||
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:label
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
multiplier:1.0 / count
|
||||
constant:0];
|
||||
|
||||
NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:label
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
|
||||
|
||||
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:label
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeHeight
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
|
||||
// set the constraints
|
||||
[NSLayoutConstraint activateConstraints:@[leftConstraint, rightConstraint, topConstraint, heightConstraint]];
|
||||
|
||||
UITapGestureRecognizer *labelTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onLabelTouch:)];
|
||||
[labelTapGesture setNumberOfTouchesRequired:1];
|
||||
[labelTapGesture setNumberOfTapsRequired:1];
|
||||
label.userInteractionEnabled = YES;
|
||||
[label addGestureRecognizer:labelTapGesture];
|
||||
|
||||
[labels addObject:label];
|
||||
}
|
||||
|
||||
sectionLabels = labels;
|
||||
|
||||
[self addSelectedMarkerView];
|
||||
|
||||
[self displaySelectedViewController];
|
||||
}
|
||||
|
||||
- (void)addSelectedMarkerView
|
||||
{
|
||||
// Sanity check
|
||||
NSAssert(sectionLabels.count, @"[SegmentedViewController] addSelectedMarkerView failed - At least one view controller is required");
|
||||
|
||||
// create the selected marker view
|
||||
selectedMarkerView = [[UIView alloc] init];
|
||||
selectedMarkerView.backgroundColor = _sectionHeaderTintColor;
|
||||
[selectedMarkerView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[self.selectionContainer addSubview:selectedMarkerView];
|
||||
|
||||
leftMarkerViewConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:[sectionLabels objectAtIndex:_selectedIndex]
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
|
||||
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
multiplier:1.0 / sectionLabels.count
|
||||
constant:0];
|
||||
|
||||
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeBottom
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.selectionContainer
|
||||
attribute:NSLayoutAttributeBottom
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
|
||||
|
||||
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:nil
|
||||
attribute:NSLayoutAttributeNotAnAttribute
|
||||
multiplier:1.0
|
||||
constant:3];
|
||||
|
||||
// set the constraints
|
||||
[NSLayoutConstraint activateConstraints:@[leftMarkerViewConstraint, widthConstraint, bottomConstraint, heightConstraint]];
|
||||
}
|
||||
|
||||
- (void)displaySelectedViewController
|
||||
{
|
||||
// Sanity check
|
||||
NSAssert(sectionLabels.count, @"[SegmentedViewController] displaySelectedViewController failed - At least one view controller is required");
|
||||
|
||||
if (_selectedViewController)
|
||||
{
|
||||
NSUInteger index = [viewControllers indexOfObject:_selectedViewController];
|
||||
|
||||
if (index != NSNotFound)
|
||||
{
|
||||
UILabel* label = [sectionLabels objectAtIndex:index];
|
||||
label.font = [UIFont systemFontOfSize:17];
|
||||
}
|
||||
|
||||
[_selectedViewController willMoveToParentViewController:nil];
|
||||
|
||||
[_selectedViewController.view removeFromSuperview];
|
||||
[_selectedViewController removeFromParentViewController];
|
||||
|
||||
[NSLayoutConstraint deactivateConstraints:@[displayedVCTopConstraint, displayedVCLeftConstraint, displayedVCWidthConstraint, displayedVCHeightConstraint]];
|
||||
}
|
||||
|
||||
UILabel* label = [sectionLabels objectAtIndex:_selectedIndex];
|
||||
label.font = [UIFont boldSystemFontOfSize:17];
|
||||
|
||||
// update the marker view position
|
||||
[NSLayoutConstraint deactivateConstraints:@[leftMarkerViewConstraint]];
|
||||
|
||||
leftMarkerViewConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:[sectionLabels objectAtIndex:_selectedIndex]
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:@[leftMarkerViewConstraint]];
|
||||
|
||||
// Set the new selected view controller
|
||||
_selectedViewController = [viewControllers objectAtIndex:_selectedIndex];
|
||||
|
||||
// Make iOS invoke selectedViewController viewWillAppear when the segmented view is already visible
|
||||
if (isViewAppeared)
|
||||
{
|
||||
[_selectedViewController beginAppearanceTransition:YES animated:YES];
|
||||
}
|
||||
|
||||
[self addChildViewController:_selectedViewController];
|
||||
|
||||
[_selectedViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
[self.viewControllerContainer addSubview:_selectedViewController.view];
|
||||
|
||||
|
||||
displayedVCTopConstraint = [NSLayoutConstraint constraintWithItem:_selectedViewController.view
|
||||
attribute:NSLayoutAttributeTop
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.viewControllerContainer
|
||||
attribute:NSLayoutAttributeTop
|
||||
multiplier:1.0f
|
||||
constant:0.0f];
|
||||
|
||||
displayedVCLeftConstraint = [NSLayoutConstraint constraintWithItem:_selectedViewController.view
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.viewControllerContainer
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0f
|
||||
constant:0.0f];
|
||||
|
||||
displayedVCWidthConstraint = [NSLayoutConstraint constraintWithItem:_selectedViewController.view
|
||||
attribute:NSLayoutAttributeWidth
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.viewControllerContainer
|
||||
attribute:NSLayoutAttributeWidth
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
displayedVCHeightConstraint = [NSLayoutConstraint constraintWithItem:_selectedViewController.view
|
||||
attribute:NSLayoutAttributeHeight
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:self.viewControllerContainer
|
||||
attribute:NSLayoutAttributeHeight
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
[NSLayoutConstraint activateConstraints:@[displayedVCTopConstraint, displayedVCLeftConstraint, displayedVCWidthConstraint, displayedVCHeightConstraint]];
|
||||
|
||||
[_selectedViewController didMoveToParentViewController:self];
|
||||
|
||||
// Make iOS invoke selectedViewController viewDidAppear when the segmented view is already visible
|
||||
if (isViewAppeared)
|
||||
{
|
||||
[_selectedViewController endAppearanceTransition];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Search
|
||||
|
||||
- (void)showSearch:(BOOL)animated
|
||||
{
|
||||
[super showSearch:animated];
|
||||
|
||||
// Show the tabs header
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseIn
|
||||
animations:^{
|
||||
|
||||
self.selectionContainerHeightConstraint.constant = 44;
|
||||
[self.view layoutIfNeeded];
|
||||
}
|
||||
completion:^(BOOL finished){
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.selectionContainerHeightConstraint.constant = 44;
|
||||
[self.view layoutIfNeeded];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hideSearch:(BOOL)animated
|
||||
{
|
||||
[super hideSearch:animated];
|
||||
|
||||
// Hide the tabs header
|
||||
if (animated)
|
||||
{
|
||||
[UIView animateWithDuration:.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseIn
|
||||
animations:^{
|
||||
|
||||
self.selectionContainerHeightConstraint.constant = 0;
|
||||
[self.view layoutIfNeeded];
|
||||
}
|
||||
completion:^(BOOL finished) {
|
||||
// Go back to the main tab
|
||||
// Do it at the end of the animation when the tabs header of the SegmentedVC is hidden
|
||||
// so that the user cannot see the selection bar of this header moving
|
||||
self.selectedIndex = 0;
|
||||
self.selectedViewController.view.hidden = NO;
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
self.selectionContainerHeightConstraint.constant = 0;
|
||||
[self.view layoutIfNeeded];
|
||||
|
||||
// Go back to the recents tab
|
||||
self.selectedIndex = 0;
|
||||
self.selectedViewController.view.hidden = NO;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - touch event
|
||||
|
||||
- (void)onLabelTouch:(UIGestureRecognizer*)gestureRecognizer
|
||||
{
|
||||
NSUInteger pos = [sectionLabels indexOfObject:gestureRecognizer.view];
|
||||
|
||||
// check if there is an update before triggering anything
|
||||
if ((pos != NSNotFound) && (_selectedIndex != pos))
|
||||
{
|
||||
// update the selected index
|
||||
self.selectedIndex = pos;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1108" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11762"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SegmentedViewController">
|
||||
<connections>
|
||||
<outlet property="selectionContainer" destination="ynH-uD-aQj" id="taa-CW-XgW"/>
|
||||
<outlet property="selectionContainerHeightConstraint" destination="fZ1-SQ-nxS" id="kQ4-n9-Gmt"/>
|
||||
<outlet property="selectionContainerTopConstraint" destination="eLe-5q-IfV" id="UhZ-9k-P1r"/>
|
||||
<outlet property="view" destination="1TG-Rn-axS" id="WxL-e2-rVK"/>
|
||||
<outlet property="viewControllerContainer" destination="Hbe-uP-aJY" id="mD3-w0-UXi"/>
|
||||
</connections>
|
||||
</placeholder>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="1TG-Rn-axS">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ynH-uD-aQj" userLabel="Selection Container">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
|
||||
<accessibility key="accessibilityConfiguration" identifier="SegmentedVCSelectionContainer"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="44" id="fZ1-SQ-nxS"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Hbe-uP-aJY" userLabel="Selected UITableView Container">
|
||||
<rect key="frame" x="0.0" y="44" width="375" height="623"/>
|
||||
<color key="tintColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<accessibility key="accessibilityConfiguration" identifier="SegmentedVCUITableViewContainer"/>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<accessibility key="accessibilityConfiguration" identifier="SegmentedVCView"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="Hbe-uP-aJY" secondAttribute="bottom" id="GHr-ci-L7A"/>
|
||||
<constraint firstItem="Hbe-uP-aJY" firstAttribute="leading" secondItem="ynH-uD-aQj" secondAttribute="leading" id="HTN-hD-pve"/>
|
||||
<constraint firstItem="ynH-uD-aQj" firstAttribute="width" secondItem="1TG-Rn-axS" secondAttribute="width" id="N0o-xo-47p"/>
|
||||
<constraint firstItem="Hbe-uP-aJY" firstAttribute="top" secondItem="ynH-uD-aQj" secondAttribute="bottom" id="Ovm-KQ-gUw"/>
|
||||
<constraint firstItem="Hbe-uP-aJY" firstAttribute="width" secondItem="1TG-Rn-axS" secondAttribute="width" id="YKU-mG-Loo"/>
|
||||
<constraint firstItem="ynH-uD-aQj" firstAttribute="leading" secondItem="1TG-Rn-axS" secondAttribute="leading" id="drw-gq-mYE"/>
|
||||
<constraint firstItem="ynH-uD-aQj" firstAttribute="top" secondItem="1TG-Rn-axS" secondAttribute="top" id="eLe-5q-IfV"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
Reference in New Issue
Block a user