mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-24 00:16:39 +02:00
dummy implementation of the segmentedViewController :
> the tar items are displayed (even if they are currently hardcoded) > the tab items can selected (the selected marker view is displayed)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket 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 "MXKViewController.h"
|
||||
|
||||
/**
|
||||
This view controller manages several uiviewcontrollers like UISegmentedControlled 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 UIView *viewControllerContainer;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *selectionContainerTopConstraint;
|
||||
|
||||
/**
|
||||
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.
|
||||
@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)index;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
Copyright 2015 OpenMarket 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"
|
||||
|
||||
@interface SegmentedViewController ()
|
||||
{
|
||||
// list of displayed UIViewControllers
|
||||
NSArray* viewControllers;
|
||||
|
||||
// list of NSString
|
||||
NSArray* sectionTitles;
|
||||
|
||||
// list of section labels
|
||||
NSArray* sectionLabels;
|
||||
|
||||
// the selected marker view
|
||||
UIView* selectedMarkerView;
|
||||
NSLayoutConstraint *leftMarkerViewConstraint;
|
||||
|
||||
// the index of the viewcontroller displayed at first load
|
||||
NSUInteger selectedIndex;
|
||||
|
||||
// the UI item color
|
||||
UIColor *greenVectorColor;
|
||||
}
|
||||
|
||||
@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)index
|
||||
{
|
||||
viewControllers = someViewControllers;
|
||||
sectionTitles = titles;
|
||||
selectedIndex = index;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)addConstraint:(UIView*)view constraint:(NSLayoutConstraint*)aConstraint
|
||||
{
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)])
|
||||
{
|
||||
[NSLayoutConstraint activateConstraints:@[aConstraint]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[view addConstraint:aConstraint];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeConstraint:(UIView*)view constraint:(NSLayoutConstraint*)aConstraint
|
||||
{
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)])
|
||||
{
|
||||
[NSLayoutConstraint deactivateConstraints:@[aConstraint]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[view removeConstraint:aConstraint];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
selectedIndex = 1;
|
||||
|
||||
// Adjust Top
|
||||
[self removeConstraint:self.view constraint: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];
|
||||
|
||||
[self addConstraint:self.selectionContainer constraint:self.selectionContainerTopConstraint];
|
||||
|
||||
// TODO : it should be an application constant value
|
||||
greenVectorColor = [UIColor colorWithRed:(98.0/256.0) green:(206.0/256.0) blue:(156.0/256.0) alpha:1.0];
|
||||
|
||||
[self createSegmentedViews];
|
||||
}
|
||||
|
||||
- (void)createSegmentedViews
|
||||
{
|
||||
NSMutableArray* labels = [[NSMutableArray alloc] init];
|
||||
|
||||
int count = 4;
|
||||
|
||||
for(int index = 0; index < count; index++)
|
||||
{
|
||||
// create programmatically each label
|
||||
UILabel *label = [[UILabel alloc] init];
|
||||
|
||||
label.text = label.text = [NSString stringWithFormat:@"toto %d", index];
|
||||
label.textAlignment = NSTextAlignmentCenter;
|
||||
label.textColor = greenVectorColor;
|
||||
label.backgroundColor = [UIColor clearColor];
|
||||
|
||||
// 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
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)])
|
||||
{
|
||||
[NSLayoutConstraint activateConstraints:@[leftConstraint, rightConstraint, topConstraint, heightConstraint]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.selectionContainer addConstraint:leftConstraint];
|
||||
[self.selectionContainer addConstraint:rightConstraint];
|
||||
[self.selectionContainer addConstraint:topConstraint];
|
||||
[label addConstraint: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
|
||||
{
|
||||
// create the selected marker view
|
||||
selectedMarkerView = [[UIView alloc] init];
|
||||
selectedMarkerView.backgroundColor = greenVectorColor;
|
||||
[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
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)])
|
||||
{
|
||||
[NSLayoutConstraint activateConstraints:@[leftMarkerViewConstraint, widthConstraint, bottomConstraint, heightConstraint]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.selectionContainer addConstraint:leftMarkerViewConstraint];
|
||||
[self.selectionContainer addConstraint:bottomConstraint];
|
||||
[selectedMarkerView addConstraint:heightConstraint];
|
||||
[selectedMarkerView addConstraint:heightConstraint];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)displaySelectedViewController
|
||||
{
|
||||
/*
|
||||
- (void) displayContentController: (UIViewController*) content;
|
||||
{
|
||||
[self addChildViewController:content];
|
||||
content.view.frame = [self frameForContentController];
|
||||
[self.view addSubview:self.currentClientView];
|
||||
[content didMoveToParentViewController:self];
|
||||
}*/
|
||||
}
|
||||
|
||||
#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
|
||||
selectedIndex = pos;
|
||||
|
||||
// update the marker view position
|
||||
[self removeConstraint:selectedMarkerView constraint:leftMarkerViewConstraint];
|
||||
|
||||
leftMarkerViewConstraint = [NSLayoutConstraint constraintWithItem:selectedMarkerView
|
||||
attribute:NSLayoutAttributeLeading
|
||||
relatedBy:NSLayoutRelationEqual
|
||||
toItem:[sectionLabels objectAtIndex:selectedIndex]
|
||||
attribute:NSLayoutAttributeLeading
|
||||
multiplier:1.0
|
||||
constant:0];
|
||||
|
||||
[self addConstraint:selectedMarkerView constraint:leftMarkerViewConstraint];
|
||||
|
||||
[self displaySelectedViewController];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8191"/>
|
||||
</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="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="600" height="600"/>
|
||||
<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="600" height="44"/>
|
||||
<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="600" height="556"/>
|
||||
<color key="tintColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<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