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

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

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

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

Q&A

解決済

1回答

2341閲覧

setViewControllers(_:direction:animated:completion:)のcompletionブロックにクロージャを渡して実行するとエラーになる

退会済みユーザー

退会済みユーザー

総合スコア0

Swift

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

0グッド

0クリップ

投稿2020/01/05 03:41

setViewControllers(_:direction:animated:completion:)のcompletionブロックにクロージャを渡して実行するとクラッシュします。
高さを変更したい特定のViewの中にはUITableViewが入っています
直し方をご存知でしたら教えて下さい。

swift

1// コードでPageViewControllerを指定ページに移動させる処理 2func movePageViewController(from: PageView?, to: PageView?, completion: ((Bool) -> Void)? = nil ) { 3 4 let sb = UIStoryboard(name: "TestVC", bundle: nil) 5 let vc = sb.instantiateInitialViewController() as! TestVC 6 7 let fromIndex: Int = from.rawValue 8 let toIndex: Int = to.rawValue 9 10 // animationDirection 11 let direction : UIPageViewController.NavigationDirection = fromIndex > toIndex ? .reverse : .forward 12 13 // presentViewController 14 subWindowPageViewController? 15 .setViewControllers([vc], direction: direction, animated: true, completion: completion) 16} 17 18// 呼び出し/ページ遷移後に特定Viewの高さを(アニメーション付きで)変える 19func testMove2(from: PageView?, to: PageView?) { 20 movePageViewController(from: PageView?, to: PageView?){ (finished) in 21 UIView.animate(withDuration:0.6, delay: 0.0, options: .curveEaseIn, animations: { 22 self.specifiedViewHieght.constant += 200 23 self.view.layoutIfNeeded() // <= ここでエラー 24 }, completion: nil) 25 } 26} 27

2020-01-05 12:16:25.217938+0900 tPageView[1812:171411] *** Assertion failure in -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3899.22.15/_UIQueuingScrollView.m:395
2020-01-05 12:16:25.221600+0900 tPageView[1812:171411] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [views count] == 3'
*** First throw call stack:
(
0 CoreFoundation 0x000000010cb1e1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010c98bb20 objc_exception_throw + 48
2 CoreFoundation 0x000000010cb1df68 +[NSException raise:format:arguments:] + 88
3 Foundation 0x000000010c3b3de9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x000000011587686a -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:] + 948
5 UIKitCore 0x0000000115879e27 -[_UIQueuingScrollView _didScrollWithAnimation:force:] + 1143
6 UIKitCore 0x00000001158759c0 -[_UIQueuingScrollView _scrollViewAnimationEnded:finished:] + 89
7 UIKitCore 0x0000000115530883 -[UIAnimator stopAnimation:] + 377
8 UIKitCore 0x0000000115530f64 -[UIAnimator _advanceAnimationsOfType:withTimestamp:] + 268
9 QuartzCore 0x0000000113b86b66 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 640
10 QuartzCore 0x0000000113c5fac3 ZL22display_timer_callbackP12__CFMachPortPvlS1 + 299
11 CoreFoundation 0x000000010ca41e8d __CFMachPortPerform + 157
12 CoreFoundation 0x000000010ca819c9 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 41
13 CoreFoundation 0x000000010ca81028 __CFRunLoopDoSource1 + 472
14 CoreFoundation 0x000000010ca7bb64 __CFRunLoopRun + 2516
15 CoreFoundation 0x000000010ca7ae66 CFRunLoopRunSpecific + 438
16 GraphicsServices 0x000000010f998bb0 GSEventRunModal + 65
17 UIKitCore 0x0000000115f55dd0 UIApplicationMain + 1621
18 tPageView 0x000000010be2c9ab main + 75
19 libdyld.dylib 0x000000010f3b0d29 start + 1
20 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

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

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

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

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

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

guest

回答1

0

ベストアンサー

アニメーション部分をメインスレッドに登録したら動きました。

swift

1// 呼び出し/ページ遷移後に特定Viewの高さを(アニメーション付きで)変える 2func testMove2(from: PageView?, to: PageView?) { 3 movePageViewController(from: PageView?, to: PageView?){ (finished) in 4 5 DispatchQueue.main.async { 6 UIView.animate(withDuration:0.6, delay: 0.0, options: .curveEaseIn, animations: { 7 self.specifiedViewHieght.constant += 200 8 self.view.layoutIfNeeded() 9 }, completion: nil) 10 } 11 } 12}

投稿2020/01/05 04:02

退会済みユーザー

退会済みユーザー

総合スコア0

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問