質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

774閲覧

【Swift】設定画面に遷移して戻ってくるとスクロールビューがずれてしまう

nakamu

総合スコア82

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/09/21 12:00

編集2019/09/21 12:18

ScrollViewは全画面表示しています。
中身もそれぞれスクリーンサイズです。
問題はポップアップでiPhoneの設定画面に1度飛んでからまたアプリに戻って来ると、
おそらくタブバーの高さ分上にズレてスクロールされてしまいます。

iPhoneの設定画面に飛ばない場合は綺麗にTikTokのようにスクリーンサイズでスクロールされます。

画像下の部分がタブバーの上部に来てしまっている。
本来はスクリーンの下に来ているので青い部分は見えない。
イメージ説明

イメージ説明
イメージ説明

スクロールビューのコンテンツを用意しているコード

swift

1func setupFirebase() { 2 3 let communityXib = UINib(nibName: "CommunityTableViewCell", bundle: Bundle(for: type(of: self))) 4 5 // 描画開始の x,y 位置 6 let px:CGFloat = 0.0 7 var py:CGFloat = 0.0 8 9 var counter = 1 10 11 db.collection("communities").getDocuments() { (querySnapshot, err) in 12 if let err = err { 13 print("Error getting documents: (err)") 14 KRProgressHUD.dismiss()// ローディング終了 15 return 16 } 17 guard querySnapshot!.documents.count > 0 else { 18 KRProgressHUD.dismiss()// ローディング終了 19 return 20 } 21 22 for document in querySnapshot!.documents { 23 print("(document.documentID) => (document.data())") 24 let communityView = communityXib.instantiate(withOwner: self, options: nil).first as! UIView 25 communityView.isUserInteractionEnabled = true 26 27 let community = document.data() 28 let documentId = document.documentID 29 30 // コミュニティー名設定 31 let titleLabel = communityView.viewWithTag(1) as! UILabel 32 let title = community["name"] as! String 33 titleLabel.textColor = UIColor.white 34 titleLabel.text = String(describing: title) 35 // コミュニティー画像設定 36 let img = communityView.viewWithTag(2) as! UIImageView 37 38 39 let storageRef = self.storage.reference() 40 let imgRef: StorageReference! 41 // 新機種 レスポンシブ 42 if UIScreen.main.nativeBounds.height == 2436 || UIScreen.main.nativeBounds.height == 2688 || UIScreen.main.nativeBounds.height == 1792 { 43 imgRef = storageRef.child("communities").child(community["imgX"] as! String) 44 } else { 45 imgRef = storageRef.child("communities").child(community["img8"] as! String) 46 } 47 img.sd_setImage(with: imgRef) 48 img.isUserInteractionEnabled = true 49 img.frame.size.height = UIScreen.main.bounds.height 50 51 let gesture = MyTapGestureRecognizer(target: self, action: #selector(ScrollViewController.btnClick(_:))) 52 gesture.targetString = documentId 53 gesture.targetData = community 54 communityView.addGestureRecognizer(gesture) 55 communityView.tag = 1 56 self.scrollView.addSubview(communityView) 57 58 // 描画開始設定 59 var viewFrame:CGRect = communityView.frame 60 viewFrame.size.width = self.scrollScreenWidth 61 viewFrame.size.height = self.scrollScreenHeight 62 viewFrame.origin = CGPoint(x: px, y: py) 63 communityView.frame = viewFrame 64 65 // 次の描画位置設定 66 py += (self.screenSize.height) 67 counter += 1 68 69 var appGuideViewFrame:CGRect = self.appGuideView.frame 70 appGuideViewFrame.size.width = self.scrollScreenWidth 71 appGuideViewFrame.size.height = self.scrollScreenHeight 72 appGuideViewFrame.origin = CGPoint(x: px, y: py) 73 self.appGuideView.frame = appGuideViewFrame 74 75 // スクロール範囲の設定 76 let nHeight:CGFloat = self.scrollScreenHeight * CGFloat(counter) 77 self.scrollView.contentSize = CGSize(width: self.scrollScreenWidth, height: nHeight) 78 79 } 80 KRProgressHUD.dismiss()// ローディング終了 81 82 } 83 84 }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

isHiddenが原因だったみたいですが、なぜバックグラウンド状態から戻って来た際に発生するのかは不明です。
対処としては消さずに遷移先で透明にしました。

Swift

1 override func viewWillAppear(_ animated: Bool) { 2 super.viewDidDisappear(animated) 3 4 let InfoVc = self.presentingViewController as! RootTabBarController 5 InfoVc.tabBar.alpha = 0 6 InfoVc.tabBar.isTranslucent = false 7 } 8 9 override func viewWillDisappear(_ animated: Bool) { 10 super.viewWillDisappear(animated) 11 12 let InfoVc = self.presentingViewController as! RootTabBarController 13 InfoVc.tabBar.alpha = 1 14 InfoVc.tabBar.isTranslucent = true 15 }

投稿2019/09/23 01:49

nakamu

総合スコア82

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問