私はかなりプログラミングに興味があるので、ちょっとした助けが必要です。ストーリーボードを使わずにスウィフトに書き込む。私はMKMapView(?)を追加したいと思いますか? UIViewについて。問題は、値/タイプをUIViewに変換できないため、できないことです。私はUIViewControllerクラスでそれを記述する必要があります。どのように私はこれを解決するつもりですか?私はどのコードをあなたに見せなければならないのか分かりません...Swift:UIViewにMapViewを配置する方法(?)
しかし、私のアプリはリンクの動画のアプリとほとんど同じです。 look att 5:08
これらのセルの1つの中にマップを配置したいと考えています。
誰かが私を助けることができます:)
編集希望:!
import UIKit
import MapKit
class ViewController: UIViewController {
var window: UIWindow?
var mapView: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
self.view.backgroundColor = UIColor.whiteColor()
self.mapView = MKMapView(frame: CGRectMake(0, 20, (self.window?.frame.width)!, 300))
self.view.addSubview(self.mapView!)
}
}
をこのブロックでは(私はここに
は私がuingよ "地図" のコードでコードを追加しますあなたがそう言うことができるなら?)私が望む細胞を変えることができますか?あなたは色を赤に変えたことが分かります。私はそこにそれを実装する必要があると思うが、私はできない。
import UIKit
import MapKit
class MapCell1: MapCell, MKMapViewDelegate {
override func setupViews() {
backgroundColor = UIColor.redColor()
}
}
そしてMapCell1がMapCellのサブクラスであり、かつMapcellは次のようになります。
import UIKit
class MapCell: BaseCell, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.grayColor() //Here can I change the color in the whole UIcollectionView. So every three cells are gray right now.
return cv
}()
let cellId = "cellId"
override func setupViews() {
super.setupViews()
addSubview(collectionView)
addconstraintsWithFormat("H:|[v0]|", views: collectionView)
addconstraintsWithFormat("V:|[v0]|", views: collectionView)
}
}
そして、これらのコードが役立つ場合、私は知らないが、私はあまりにもそれらを追加。
import UIKit
class BaseCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
func setupViews() {
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
class BaseCell: UICollectionViewCell {
func setupViews() {
}
}
}
そして
import UIKit
class MenuBar: UIView, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.rgb(61, green: 91, blue: 151)
cv.dataSource = self
cv.delegate = self
return cv
}()
let cellId = "cellId"
let imageNames = ["LocationMarker", "MapFeed", "ProfilePicture" ]
var viewController: ViewController?
override init(frame: CGRect) {
super.init(frame: frame)
collectionView.registerClass(MenuCell.self, forCellWithReuseIdentifier: cellId)
addSubview(collectionView)
addconstraintsWithFormat("H:|[v0]|", views: collectionView)
addconstraintsWithFormat("V:|[v0]|", views: collectionView)
let selectedIndexPath = NSIndexPath(forItem: 0, inSection: 0)
collectionView.selectItemAtIndexPath(selectedIndexPath, animated: false, scrollPosition: .None)
setupHorizontalBar()
}
var horizontalBarLefAnchorConstraint: NSLayoutConstraint?
func setupHorizontalBar() {
let horizontalBarView = UIView()
horizontalBarView.backgroundColor = UIColor.whiteColor()
horizontalBarView.translatesAutoresizingMaskIntoConstraints = false
addSubview(horizontalBarView)
horizontalBarLefAnchorConstraint = horizontalBarView.leftAnchor.constraintEqualToAnchor(self.leftAnchor)
horizontalBarLefAnchorConstraint?.active = true
horizontalBarView.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true
horizontalBarView.widthAnchor.constraintEqualToAnchor(self.widthAnchor, multiplier: 1/4).active = true
horizontalBarView.heightAnchor.constraintEqualToConstant(4).active = true
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// print(indexPath.item)
// let x = CGFloat(indexPath.item) * frame.width/2.65
// horizontalBarLefAnchorConstraint?.constant = x
//
// UIView.animateWithDuration(0.75, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .CurveEaseOut, animations: {
// self.layoutIfNeeded()
//
}, completion: nil)
viewController?.scrollToMenuIndex(indexPath.item)
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellId, forIndexPath: indexPath) as! MenuCell
cell.imageView.image = UIImage(named: imageNames[indexPath.item])?.imageWithRenderingMode(.AlwaysTemplate)
cell.tintColor = UIColor.rgb(39, green: 58, blue: 97)
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSizeMake(frame.width/3, frame.height)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class MenuCell: BaseCell {
let imageView: UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named: "LocationMarker")?.imageWithRenderingMode(.AlwaysTemplate)
iv.tintColor = UIColor.rgb(39, green: 58, blue: 97)
return iv
}()
override var highlighted: Bool {
didSet {
imageView.tintColor = highlighted ? UIColor.whiteColor() : UIColor.rgb(39, green: 58, blue: 97)
}
}
override var selected: Bool {
didSet {
imageView.tintColor = selected ? UIColor.whiteColor() : UIColor.rgb(39, green: 58, blue: 97)
}
}
override func setupViews() {
super.setupViews()
addSubview(imageView)
addconstraintsWithFormat("H:[v0(28)]", views: imageView)
addconstraintsWithFormat("V:[v0(28)]", views: imageView)
addConstraint(NSLayoutConstraint(item: imageView, attribute: .CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: imageView, attribute: .CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0))
}
}
ここにコードを追加してください。動画は時間の経過とともに消えてしまい、動画を見ることは人々があなたの質問に答えるための入り口になる大きな障壁となります。 ようこそ。可能な限り詳細に書式を設定して、回答が他人や自分自身を助けることができるようにしてください。 – DynamiteReed
@ BlueJ774によれば、これはあなたの問題をはっきりと説明する上で重要です。また、その問題を解決しようとする試みについて説明してください。そうすれば、他の人はあなたが答えを待っているだけでなく、すでに試したことがあるかどうかを推測する必要もないでしょう(既に試した答えはありません))。これの良い例は、相対的な質問のリンクや、試したチュートリアルへのリンクを追加することです。 – RomOne
応答とヒントをありがとう、私は今、somコードを追加して、私はそれが助けてくれることを願って:) –