From 5d993c51d4defec4f4dad2224fbddd00474860bd Mon Sep 17 00:00:00 2001 From: Ufuk Tugay <ufukkaantugay@gmail.com> Date: Tue, 22 Jun 2021 19:33:50 +0200 Subject: [PATCH] added clickable table cells for detection selection --- .../project.pbxproj | 20 ++++++ .../Base.lproj/Main.storyboard | 70 ++++++++++++++----- .../ObjectSelector.swift | 43 ++++++++++++ .../objectsTableViewCell.swift | 41 +++++++++++ .../objectsTableViewCell.xib | 41 +++++++++++ 5 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 Objekterkennung in AR mit ARKit und CoreML/ObjectSelector.swift create mode 100644 Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.swift create mode 100644 Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.xib diff --git a/Objekterkennung in AR mit ARKit und CoreML.xcodeproj/project.pbxproj b/Objekterkennung in AR mit ARKit und CoreML.xcodeproj/project.pbxproj index ddc3d4e..5ae4d07 100644 --- a/Objekterkennung in AR mit ARKit und CoreML.xcodeproj/project.pbxproj +++ b/Objekterkennung in AR mit ARKit und CoreML.xcodeproj/project.pbxproj @@ -14,7 +14,10 @@ 291C32C0267B6A3600A7A0D3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 291C32BF267B6A3600A7A0D3 /* Assets.xcassets */; }; 291C32C3267B6A3600A7A0D3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 291C32C1267B6A3600A7A0D3 /* LaunchScreen.storyboard */; }; 291C32CB267B6DD800A7A0D3 /* StartScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291C32CA267B6DD800A7A0D3 /* StartScreen.swift */; }; + 297364A8268241C600C3A1CF /* objectsTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 297364A6268241C600C3A1CF /* objectsTableViewCell.swift */; }; + 297364A9268241C600C3A1CF /* objectsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 297364A7268241C600C3A1CF /* objectsTableViewCell.xib */; }; 2998FFAE267CD58600ABD190 /* ObjectDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2998FFAD267CD58600ABD190 /* ObjectDetector.swift */; }; + 2998FFB22680D45900ABD190 /* ObjectSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2998FFB12680D45900ABD190 /* ObjectSelector.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -27,7 +30,10 @@ 291C32C2267B6A3600A7A0D3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 291C32C4267B6A3600A7A0D3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 291C32CA267B6DD800A7A0D3 /* StartScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartScreen.swift; sourceTree = "<group>"; }; + 297364A6268241C600C3A1CF /* objectsTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = objectsTableViewCell.swift; sourceTree = "<group>"; }; + 297364A7268241C600C3A1CF /* objectsTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = objectsTableViewCell.xib; sourceTree = "<group>"; }; 2998FFAD267CD58600ABD190 /* ObjectDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectDetector.swift; sourceTree = "<group>"; }; + 2998FFB12680D45900ABD190 /* ObjectSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectSelector.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -46,6 +52,7 @@ children = ( 291C32B5267B6A3400A7A0D3 /* Objekterkennung in AR mit ARKit und CoreML */, 291C32B4267B6A3400A7A0D3 /* Products */, + 297364AA268255E100C3A1CF /* Submodules */, ); sourceTree = "<group>"; }; @@ -65,14 +72,24 @@ 291C32BA267B6A3400A7A0D3 /* ViewController.swift */, 291C32CA267B6DD800A7A0D3 /* StartScreen.swift */, 291C32BC267B6A3400A7A0D3 /* Main.storyboard */, + 2998FFB12680D45900ABD190 /* ObjectSelector.swift */, 2998FFAD267CD58600ABD190 /* ObjectDetector.swift */, 291C32BF267B6A3600A7A0D3 /* Assets.xcassets */, 291C32C1267B6A3600A7A0D3 /* LaunchScreen.storyboard */, 291C32C4267B6A3600A7A0D3 /* Info.plist */, + 297364A6268241C600C3A1CF /* objectsTableViewCell.swift */, + 297364A7268241C600C3A1CF /* objectsTableViewCell.xib */, ); path = "Objekterkennung in AR mit ARKit und CoreML"; sourceTree = "<group>"; }; + 297364AA268255E100C3A1CF /* Submodules */ = { + isa = PBXGroup; + children = ( + ); + path = Submodules; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -134,6 +151,7 @@ 291C32C3267B6A3600A7A0D3 /* LaunchScreen.storyboard in Resources */, 291C32C0267B6A3600A7A0D3 /* Assets.xcassets in Resources */, 291C32BE267B6A3400A7A0D3 /* Main.storyboard in Resources */, + 297364A9268241C600C3A1CF /* objectsTableViewCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -148,6 +166,8 @@ 291C32BB267B6A3400A7A0D3 /* ViewController.swift in Sources */, 291C32B7267B6A3400A7A0D3 /* AppDelegate.swift in Sources */, 291C32CB267B6DD800A7A0D3 /* StartScreen.swift in Sources */, + 297364A8268241C600C3A1CF /* objectsTableViewCell.swift in Sources */, + 2998FFB22680D45900ABD190 /* ObjectSelector.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Objekterkennung in AR mit ARKit und CoreML/Base.lproj/Main.storyboard b/Objekterkennung in AR mit ARKit und CoreML/Base.lproj/Main.storyboard index 62cb809..a074ea8 100644 --- a/Objekterkennung in AR mit ARKit und CoreML/Base.lproj/Main.storyboard +++ b/Objekterkennung in AR mit ARKit und CoreML/Base.lproj/Main.storyboard @@ -17,7 +17,7 @@ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gZn-ez-RhR"> - <rect key="frame" x="0.0" y="50" width="834" height="1062"/> + <rect key="frame" x="0.0" y="0.0" width="834" height="1112"/> <subviews> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" id="DKE-En-LAf"> <rect key="frame" x="0.0" y="482" width="834" height="98"/> @@ -26,7 +26,7 @@ <color key="titleColor" systemColor="linkColor"/> </state> <connections> - <segue destination="BV1-FR-VrT" kind="show" id="iY2-FR-de1"/> + <segue destination="bzU-wY-V5a" kind="show" id="C7A-GD-02X"/> </connections> </button> </subviews> @@ -39,11 +39,14 @@ <viewLayoutGuide key="safeArea" id="sSH-U5-j3N"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> <constraints> + <constraint firstItem="gZn-ez-RhR" firstAttribute="trailing" secondItem="sSH-U5-j3N" secondAttribute="trailing" id="7jX-dB-4lT"/> + <constraint firstItem="gZn-ez-RhR" firstAttribute="top" secondItem="Owh-FO-GX2" secondAttribute="top" id="Gbc-Hx-mFD"/> + <constraint firstItem="sSH-U5-j3N" firstAttribute="bottom" secondItem="gZn-ez-RhR" secondAttribute="bottom" id="Oy6-hQ-rjG"/> <constraint firstItem="gZn-ez-RhR" firstAttribute="trailing" secondItem="sSH-U5-j3N" secondAttribute="trailing" id="P47-mh-cmK"/> <constraint firstItem="gZn-ez-RhR" firstAttribute="bottom" secondItem="sSH-U5-j3N" secondAttribute="bottom" id="RGA-69-VVT"/> <constraint firstItem="gZn-ez-RhR" firstAttribute="trailing" secondItem="sSH-U5-j3N" secondAttribute="trailing" id="Ujw-Zs-bmI"/> - <constraint firstItem="gZn-ez-RhR" firstAttribute="top" secondItem="sSH-U5-j3N" secondAttribute="top" id="jlP-tO-owA"/> <constraint firstItem="gZn-ez-RhR" firstAttribute="leading" secondItem="sSH-U5-j3N" secondAttribute="leading" id="kxj-NO-8eW"/> + <constraint firstItem="gZn-ez-RhR" firstAttribute="leading" secondItem="sSH-U5-j3N" secondAttribute="leading" id="yaE-cO-uVY"/> </constraints> </view> <navigationItem key="navigationItem" id="CcB-7n-HCS"/> @@ -53,6 +56,21 @@ <point key="canvasLocation" x="774.8201438848921" y="17.805755395683455"/> </scene> <!--View Controller--> + <scene sceneID="TPO-2f-2Nn"> + <objects> + <viewController id="EeJ-BJ-sgf" sceneMemberID="viewController"> + <view key="view" contentMode="scaleToFill" id="gdf-R6-yPu"> + <rect key="frame" x="0.0" y="0.0" width="834" height="1112"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <viewLayoutGuide key="safeArea" id="lai-Bh-bDT"/> + <color key="backgroundColor" systemColor="systemBackgroundColor"/> + </view> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="GpX-jq-vfw" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="775" y="792"/> + </scene> + <!--View Controller--> <scene sceneID="tXr-a1-R10"> <objects> <viewController id="BV1-FR-VrT" customClass="ViewController" customModule="Objekterkennung_in_AR_mit_ARKit_und_CoreML" customModuleProvider="target" sceneMemberID="viewController"> @@ -61,16 +79,8 @@ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <subviews> <arscnView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BrB-h1-WRS"> - <rect key="frame" x="0.0" y="50" width="834" height="1062"/> + <rect key="frame" x="0.0" y="0.0" width="834" height="1112"/> </arscnView> - <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="c0q-pK-UW8"> - <rect key="frame" x="180" y="622" width="88" height="30"/> - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> - <state key="normal" title="BackToMenu"/> - <connections> - <segue destination="tzj-kJ-pWl" kind="presentation" modalPresentationStyle="fullScreen" id="cDN-nb-bA1"/> - </connections> - </button> </subviews> <viewLayoutGuide key="safeArea" id="fQZ-KI-GVf"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/> @@ -83,21 +93,18 @@ <constraint firstItem="BrB-h1-WRS" firstAttribute="bottom" secondItem="fQZ-KI-GVf" secondAttribute="bottom" id="VpT-BR-CcM"/> <constraint firstItem="BrB-h1-WRS" firstAttribute="trailing" secondItem="fQZ-KI-GVf" secondAttribute="trailing" id="XyZ-9z-H8e"/> <constraint firstItem="BrB-h1-WRS" firstAttribute="trailing" secondItem="fQZ-KI-GVf" secondAttribute="trailing" id="Y0j-AT-0ts"/> - <constraint firstItem="BrB-h1-WRS" firstAttribute="top" secondItem="U0K-SW-4ec" secondAttribute="top" id="cHK-o1-Ewb"/> <constraint firstAttribute="bottom" secondItem="BrB-h1-WRS" secondAttribute="bottom" id="fyC-ey-8FC"/> <constraint firstItem="BrB-h1-WRS" firstAttribute="leading" secondItem="fQZ-KI-GVf" secondAttribute="leading" id="oqE-tG-7YC"/> - <constraint firstItem="BrB-h1-WRS" firstAttribute="top" secondItem="U0K-SW-4ec" secondAttribute="top" id="rJc-2c-zQA"/> </constraints> </view> <navigationItem key="navigationItem" id="BKG-QV-U3d"/> <connections> - <outlet property="BackToMenu" destination="c0q-pK-UW8" id="4Kp-ah-X3k"/> <outlet property="sceneView" destination="BrB-h1-WRS" id="5nT-qQ-ynl"/> </connections> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="1461.1510791366907" y="17.805755395683455"/> + <point key="canvasLocation" x="2479" y="18"/> </scene> <!--Navigation Controller--> <scene sceneID="VZm-xT-bd3"> @@ -117,6 +124,37 @@ </objects> <point key="canvasLocation" x="78.417266187050359" y="17.805755395683455"/> </scene> + <!--Table Controller--> + <scene sceneID="Xua-Zi-N5o"> + <objects> + <viewController id="bzU-wY-V5a" customClass="tableController" customModule="Objekterkennung_in_AR_mit_ARKit_und_CoreML" customModuleProvider="target" sceneMemberID="viewController"> + <view key="view" contentMode="scaleToFill" id="ioa-NU-4rv"> + <rect key="frame" x="0.0" y="0.0" width="834" height="1112"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <subviews> + <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="5x0-4P-V2A"> + <rect key="frame" x="0.0" y="50" width="834" height="1062"/> + <color key="backgroundColor" systemColor="systemBackgroundColor"/> + </tableView> + </subviews> + <viewLayoutGuide key="safeArea" id="xGo-gE-Xz5"/> + <color key="backgroundColor" systemColor="systemBackgroundColor"/> + <constraints> + <constraint firstItem="xGo-gE-Xz5" firstAttribute="bottom" secondItem="5x0-4P-V2A" secondAttribute="bottom" id="0ZY-sM-yWn"/> + <constraint firstItem="xGo-gE-Xz5" firstAttribute="trailing" secondItem="5x0-4P-V2A" secondAttribute="trailing" id="6r7-bQ-X4Y"/> + <constraint firstItem="5x0-4P-V2A" firstAttribute="top" secondItem="xGo-gE-Xz5" secondAttribute="top" id="WC4-uY-wDs"/> + <constraint firstItem="5x0-4P-V2A" firstAttribute="leading" secondItem="xGo-gE-Xz5" secondAttribute="leading" id="xm1-dN-VNP"/> + </constraints> + </view> + <navigationItem key="navigationItem" id="Omd-4T-LxI"/> + <connections> + <outlet property="table" destination="5x0-4P-V2A" id="KCo-qw-s1n"/> + </connections> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="RFp-NP-Yep" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="1558" y="18"/> + </scene> </scenes> <resources> <systemColor name="linkColor"> diff --git a/Objekterkennung in AR mit ARKit und CoreML/ObjectSelector.swift b/Objekterkennung in AR mit ARKit und CoreML/ObjectSelector.swift new file mode 100644 index 0000000..a3b8aa5 --- /dev/null +++ b/Objekterkennung in AR mit ARKit und CoreML/ObjectSelector.swift @@ -0,0 +1,43 @@ +// +// ObjectSelector.swift +// Objekterkennung in AR mit ARKit und CoreML +// +// Created by Ufuk Kaan on 21.06.21. +// + +import UIKit + +class tableController: UIViewController, UITableViewDataSource{ + + + @IBOutlet var table: UITableView! + + let data = ["First", "Second"] + + override func viewDidLoad() { + super.viewDidLoad() + table.register(objectsTableViewCell.nib(), forCellReuseIdentifier: objectsTableViewCell.identifier) + table.dataSource = self + } + + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return data.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: objectsTableViewCell.identifier, for: indexPath) as! objectsTableViewCell + cell.configure(with: data[indexPath.row]) + cell.delegate = self + + return cell + } + +} + +extension tableController: objectsTableViewCellDelegate { + func didTapButton(with title: String) { + + + } +} diff --git a/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.swift b/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.swift new file mode 100644 index 0000000..37a7045 --- /dev/null +++ b/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.swift @@ -0,0 +1,41 @@ +// +// objectsTableViewCell.swift +// Objekterkennung in AR mit ARKit und CoreML +// +// Created by Ufuk Kaan on 22.06.21. +// + +import UIKit +import BFWControls + +protocol objectsTableViewCellDelegate: AnyObject{ + func didTapButton(with title: String) +} +class objectsTableViewCell: UITableViewCell { + + weak var delegate: objectsTableViewCellDelegate? + + static let identifier = "objectsTableViewCell" + + static func nib() -> UINib{ + return UINib(nibName: "objectsTableViewCell", bundle: nil) + } + @IBOutlet var button: UIButton! + private var title: String = "" + @IBAction func didTapButton(){ + delegate?.didTapButton(with: title) + + } + func configure(with title: String){ + self.title = title + button.setTitle(title, for: .normal) + } + + override func awakeFromNib() { + super.awakeFromNib() + button.setTitleColor(.link, for: .normal) + } + + + +} diff --git a/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.xib b/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.xib new file mode 100644 index 0000000..801e33f --- /dev/null +++ b/Objekterkennung in AR mit ARKit und CoreML/objectsTableViewCell.xib @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> + <device id="retina6_1" orientation="portrait" appearance="light"/> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/> + <capability name="Safe area layout guides" minToolsVersion="9.0"/> + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> + </dependencies> + <objects> + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/> + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> + <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="objectsTableViewCell" rowHeight="65" id="KGk-i7-Jjw" customClass="objectsTableViewCell" customModule="Objekterkennung_in_AR_mit_ARKit_und_CoreML" customModuleProvider="target"> + <rect key="frame" x="0.0" y="0.0" width="379" height="65"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM"> + <rect key="frame" x="0.0" y="0.0" width="379" height="65"/> + <autoresizingMask key="autoresizingMask"/> + <subviews> + <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bJD-Ce-Fjd"> + <rect key="frame" x="0.0" y="0.0" width="379" height="65"/> + <state key="normal" title="Test Object"/> + <connections> + <action selector="didTapButton" destination="KGk-i7-Jjw" eventType="touchUpInside" id="LRI-QZ-Q1R"/> + </connections> + </button> + </subviews> + <constraints> + <constraint firstAttribute="bottom" secondItem="bJD-Ce-Fjd" secondAttribute="bottom" id="5tF-Ff-CwO"/> + <constraint firstItem="bJD-Ce-Fjd" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" id="RNm-Ge-u1O"/> + <constraint firstAttribute="trailing" secondItem="bJD-Ce-Fjd" secondAttribute="trailing" id="nID-f1-qgH"/> + <constraint firstItem="bJD-Ce-Fjd" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" id="nkP-dW-ZyD"/> + </constraints> + </tableViewCellContentView> + <viewLayoutGuide key="safeArea" id="njF-e1-oar"/> + <connections> + <outlet property="button" destination="bJD-Ce-Fjd" id="HFE-Q1-HuF"/> + </connections> + <point key="canvasLocation" x="180.43478260869566" y="51.897321428571423"/> + </tableViewCell> + </objects> +</document> -- GitLab