Просмотр исходного кода

Implemented basic section selector

Inigo Valentin 10 лет назад
Родитель
Сommit
ebfff850a0

BIN
app.xcodeproj/project.xcworkspace/xcuserdata/seavenois.xcuserdatad/UserInterfaceState.xcuserstate


+ 31 - 4
app/Base.lproj/Main.storyboard

@@ -99,36 +99,49 @@
                                     <outlet property="delegate" destination="BYZ-38-t0r" id="k4t-RF-DxW"/>
                                     <outlet property="delegate" destination="BYZ-38-t0r" id="k4t-RF-DxW"/>
                                 </connections>
                                 </connections>
                             </collectionView>
                             </collectionView>
-                            <containerView opaque="NO" contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FfD-xR-Ufj">
+                            <containerView opaque="NO" contentMode="scaleToFill" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="FfD-xR-Ufj" userLabel="Container View Home">
                                 <frame key="frameInset" height="381" maxY="-5"/>
                                 <frame key="frameInset" height="381" maxY="-5"/>
                                 <connections>
                                 <connections>
-                                    <segue destination="aNc-O2-1Df" kind="embed" id="QXk-51-7xE"/>
+                                    <segue destination="aNc-O2-1Df" kind="embed" id="DGi-yn-SV1"/>
+                                </connections>
+                            </containerView>
+                            <containerView opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="T4H-Rn-I4y" userLabel="Container View Location">
+                                <frame key="frameInset" minX="38" height="128" maxX="42" maxY="126"/>
+                                <connections>
+                                    <segue destination="Xnt-cB-Rqv" kind="embed" id="tDq-Wx-d8o"/>
                                 </connections>
                                 </connections>
                             </containerView>
                             </containerView>
                         </subviews>
                         </subviews>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <constraints>
                         <constraints>
+                            <constraint firstItem="T4H-Rn-I4y" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="3Eh-im-76c"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="top" secondItem="zFh-si-6JY" secondAttribute="bottom" id="779-4E-igL"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="top" secondItem="zFh-si-6JY" secondAttribute="bottom" id="779-4E-igL"/>
                             <constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="FfD-xR-Ufj" secondAttribute="bottom" id="7jk-ze-1Vp"/>
                             <constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="FfD-xR-Ufj" secondAttribute="bottom" id="7jk-ze-1Vp"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="leading" secondItem="Ikv-46-g2m" secondAttribute="leading" id="DtH-3x-QsB"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="leading" secondItem="Ikv-46-g2m" secondAttribute="leading" id="DtH-3x-QsB"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="HNI-Oh-agx"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="HNI-Oh-agx"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="MPS-z3-zNb"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="MPS-z3-zNb"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="MZQ-hn-ezh"/>
                             <constraint firstItem="zFh-si-6JY" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="MZQ-hn-ezh"/>
+                            <constraint firstItem="T4H-Rn-I4y" firstAttribute="top" secondItem="Ikv-46-g2m" secondAttribute="bottom" id="UAm-na-Ilc"/>
+                            <constraint firstItem="T4H-Rn-I4y" firstAttribute="centerX" secondItem="Ikv-46-g2m" secondAttribute="centerX" id="a3W-7J-vjF"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="eln-ck-QcI"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="eln-ck-QcI"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="top" secondItem="Ikv-46-g2m" secondAttribute="bottom" id="fwz-Vq-Hzc"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="top" secondItem="Ikv-46-g2m" secondAttribute="bottom" id="fwz-Vq-Hzc"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="j8o-dm-xpa"/>
                             <constraint firstItem="Ikv-46-g2m" firstAttribute="width" secondItem="8bC-Xf-vdC" secondAttribute="width" id="j8o-dm-xpa"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="centerX" secondItem="Ikv-46-g2m" secondAttribute="centerX" id="kSp-hr-GIX"/>
                             <constraint firstItem="FfD-xR-Ufj" firstAttribute="centerX" secondItem="Ikv-46-g2m" secondAttribute="centerX" id="kSp-hr-GIX"/>
                         </constraints>
                         </constraints>
                     </view>
                     </view>
+                    <connections>
+                        <outlet property="containerViewHome" destination="FfD-xR-Ufj" id="EtF-qz-vWE"/>
+                        <outlet property="containerViewLocation" destination="T4H-Rn-I4y" id="EFa-Km-WuR"/>
+                    </connections>
                 </viewController>
                 </viewController>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
             </objects>
             </objects>
             <point key="canvasLocation" x="789.60000000000002" y="899.10044977511257"/>
             <point key="canvasLocation" x="789.60000000000002" y="899.10044977511257"/>
         </scene>
         </scene>
-        <!--View Controller-->
+        <!--Home-->
         <scene sceneID="DhP-V4-Fb2">
         <scene sceneID="DhP-V4-Fb2">
             <objects>
             <objects>
-                <viewController storyboardIdentifier="homeViewControllerScene" id="aNc-O2-1Df" sceneMemberID="viewController">
+                <viewController storyboardIdentifier="homeViewControllerScene" title="Home" id="aNc-O2-1Df" sceneMemberID="viewController">
                     <view key="view" contentMode="scaleToFill" id="12o-6g-8cT">
                     <view key="view" contentMode="scaleToFill" id="12o-6g-8cT">
                         <rect key="frame" x="0.0" y="0.0" width="320" height="381"/>
                         <rect key="frame" x="0.0" y="0.0" width="320" height="381"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -139,5 +152,19 @@
             </objects>
             </objects>
             <point key="canvasLocation" x="454" y="1646"/>
             <point key="canvasLocation" x="454" y="1646"/>
         </scene>
         </scene>
+        <!--Location-->
+        <scene sceneID="LiN-jX-2oB">
+            <objects>
+                <viewController title="Location" id="Xnt-cB-Rqv" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="hp8-jo-hEx">
+                        <rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <color key="backgroundColor" red="1" green="0.055437682639999999" blue="0.9161184698" alpha="1" colorSpace="calibratedRGB"/>
+                    </view>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="r7U-0f-tjM" userLabel="First Responder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="1234" y="1473"/>
+        </scene>
     </scenes>
     </scenes>
 </document>
 </document>

+ 26 - 28
app/ViewController.swift

@@ -9,7 +9,11 @@
 import UIKit
 import UIKit
 
 
 class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
 class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
+    
+    var sectionCollection: UICollectionView!
 
 
+    @IBOutlet weak var containerViewLocation: UIView!
+    @IBOutlet weak var containerViewHome: UIView!
     override func viewDidLoad() {
     override func viewDidLoad() {
         print("LOAD")
         print("LOAD")
         super.viewDidLoad()
         super.viewDidLoad()
@@ -40,15 +44,10 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
         //Get a reference to our storyboard cell
         //Get a reference to our storyboard cell
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
         
         
-        //Make the updatable
-        //cell.setNeedsDisplay()
-        //cell.setNeedsLayout()
-        
         //Set text
         //Set text
         cell.label.text = self.items[indexPath.item]
         cell.label.text = self.items[indexPath.item]
         
         
         
         
-        
         //Mark the first cell as selected
         //Mark the first cell as selected
         if indexPath.item == selected{
         if indexPath.item == selected{
             cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
             cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
@@ -65,13 +64,17 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
     // MARK: - UICollectionViewDelegate protocol
     // MARK: - UICollectionViewDelegate protocol
     
     
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-        // Return all labels to their original state, and mark the selected as such
+        sectionCollection = collectionView
+        print("You selected cell #\(indexPath.item)!")
+        showComponent(selected: indexPath.item)
+    }
+    
+    @IBAction func showComponent(selected: Int) {
+        print("SELECTED: \(selected)")
+        //Activate label
         var i = 0
         var i = 0
-        selected = indexPath.item
-        for cell in collectionView.visibleCells as! [MenuCollectionViewCell]{
-            print("\(i)/\(indexPath.item)")
-            if i == indexPath.item{
-                print("CHANGE")
+        for cell in sectionCollection.visibleCells as! [MenuCollectionViewCell]{
+            if i == selected + 1{
                 cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
                 cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
                 cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
                 cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
             }
             }
@@ -80,26 +83,21 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
                 cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
                 cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
                 
                 
             }
             }
-            //cell.superview?.superview?.setNeedsDisplay()
-            //cell.setNeedsLayout()
-            //DispatchQueue.main.async{cell.setNeedsDisplay()}
             i = i + 1
             i = i + 1
         }
         }
-        print("REDRAW")
-        //collectionView.setNeedsDisplay()
-        collectionView.layoutIfNeeded()
-        //collectionView.setNeedsLayout()
-        //DispatchQueue.main.async{collectionView.setNeedsDisplay()}
-        //dispatch_async(dispatch_get_main_queue(), {collectionView.setNeedsDisplay()})
         
         
-            
-        
-        //Mark the selected one
-        //let sel = collectionView.visibleCells as! [[MenuCollectionViewCell]indexPath]
-        
-        
-        //let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
-        print("You selected cell #\(indexPath.item)!")
+        //Show the view
+        if selected == 0 {
+            UIView.animate(withDuration: 0.5, animations: {
+                self.containerViewHome.alpha = 1
+                self.containerViewLocation.alpha = 0
+            })
+        } else if selected == 1 {
+            UIView.animate(withDuration: 0.5, animations: {
+                self.containerViewHome.alpha = 0
+                self.containerViewLocation.alpha = 1
+            })
+        }
     }
     }