iOS 8 Tap on UITextView freezes the app - ios

I have an old code, without ARC, without Autolayout and I am constructing theUITableViewCell programmatically. TheUITableViewCell contains aUITextView. The cell is constructed properly but when I tap on theUITextView for editing the app freezes and after some time it exists (I think it's because it's taking a lot of CPU Time). This only happens with iOS 8, other versions it works fine.
I debugged and I do getUIKeyboardWillShowNotification notification but the keyboard does not show up and I can't do anything after this.
Below is the code
// Register notification when the keyboard will be show
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
// Register notification when the keyboard will be hide
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
CGRect frame = CGRectMake(MIN_X,(LABEL_HEIGHT + VERTICAL_PADDING) + 2,TEXT_BOX_WIDTH,TEXT_BOX_HEIGHT);
self.roundRectView = [[RoundRectView alloc]initWithFrame:frame];
self.roundRectView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:roundRectView];
inputTextView = [[UITextView alloc] initWithFrame:frame];
inputTextView.editable = YES;
inputTextView.delegate = self;
if(self.parameter.selectedValue == nil || [self.parameter.selectedValue length] == 0){
inputTextView.text = self.parameter.label;
}
else{
inputTextView.text = self.parameter.selectedValue;
}
inputTextView.backgroundColor = [UIColor clearColor];
inputTextView.textAlignment = UITextAlignmentLeft;
inputTextView.font = [UIFont fontWithName:#"HelveticaNeue" size:15.0];
inputTextView.textColor = [UIColor grayColor];
inputTextView.scrollEnabled = NO;
inputTextView.bounces = NO;
inputTextView.autocorrectionType = UITextAutocorrectionTypeNo;
[self.contentView addSubview:inputTextView];
Below is theUIKeyboardWillShowNotification handler :-
-(void) keyboardWillShow:(NSNotification *)note{
if([self.inputTextView isFirstResponder]) {
// Get the keyboard size
CGRect keyboardBounds;
[[note.userInfo valueForKey:UIKeyboardFrameBeginUserInfoKey] getValue: &keyboardBounds];
// Detect orientation
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect frame = self.parentTableView.frame;
// Start animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.3f];
// Reduce size of the Table view
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
frame.size.height -= keyboardBounds.size.height-100;
else
frame.size.height -= keyboardBounds.size.width-100;
// Apply new size of table view
self.parentTableView.frame = frame;
// Scroll the table view to see the TextField just above the keyboard
if (self.inputTextView)
{
CGRect textFieldRect = [self.parentTableView convertRect:self.inputTextView.bounds fromView:self.inputTextView];
[self.parentTableView scrollRectToVisible:textFieldRect animated:NO];
}
[UIView commitAnimations];
}}
Below is the crash report. My app name is "My App"
Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread: 0
Application Specific Information:
com.myapp.app failed to exit in time
Elapsed total CPU time (seconds): 8.070 (user 8.070, system 0.000), 66% CPU
Elapsed application CPU time (seconds): 5.689, 47% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 QuartzCore 0x27e013ca x_hash_table_lookup + 62
1 QuartzCore 0x27e10c60 CAMediaTimingCopyRenderTiming + 120
2 QuartzCore 0x27e0fd4a CA::Layer::add_animation(CAAnimation*, __CFString const*) + 650
3 QuartzCore 0x27e0f876 -[CALayer addAnimation:forKey:] + 478
4 UIKit 0x28673c4c __67-[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:]_block_invoke + 376
5 UIKit 0x28673a98 -[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 544
6 QuartzCore 0x27e02788 CA::Layer::end_change(CA::Transaction*, unsigned int, objc_object*) + 92
7 QuartzCore 0x27e03322 CA::Layer::set_bounds(CA::Rect const&, bool) + 522
8 QuartzCore 0x27e03046 -[CALayer setBounds:] + 106
9 QuartzCore 0x27e0407a -[CALayer setFrame:] + 538
10 UIKit 0x283dcfde -[UIView(Geometry) setFrame:] + 250
11 UIKit 0x283f7408 -[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] + 804
12 UIKit 0x283f70d2 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 254
13 CoreFoundation 0x24e6506e __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 86
14 CoreFoundation 0x24e64f68 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 200
15 UIKit 0x283e7bea -[UIView(Geometry) resizeSubviewsWithOldSize:] + 114
16 UIKit 0x283dd0f2 -[UIView(Geometry) setFrame:] + 526
17 UIKit 0x28469320 -[UILayoutContainerView setFrame:] + 56
18 UIKit 0x283f7408 -[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] + 804
19 UIKit 0x283f70d2 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 254
20 CoreFoundation 0x24e6506e __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 86
21 CoreFoundation 0x24e64f68 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 200
22 UIKit 0x283e7bea -[UIView(Geometry) resizeSubviewsWithOldSize:] + 114
23 UIKit 0x28429b40 -[UIView(Geometry) setBounds:] + 476
24 UIKit 0x288b7ad8 -[UIDropShadowView setBounds:] + 124
25 UIKit 0x287cdf84 -[_UIFormSheetPresentationController containerViewWillLayoutSubviews] + 272
26 UIKit 0x283e0154 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 440
27 QuartzCore 0x27e0bf60 -[CALayer layoutSublayers] + 132
28 QuartzCore 0x27e0794c CA::Layer::layout_if_needed(CA::Transaction*) + 356
29 UIKit 0x283f28e6 -[UIView(Hierarchy) layoutBelowIfNeeded] + 134
30 UIKit 0x28413d22 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 474
31 UIKit 0x28413b3e +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:] + 62
32 UIKit 0x287cdb44 -[_UIFormSheetPresentationController _changeLayoutModeToAvoidKeyboard:] + 220
33 CoreFoundation 0x24ef6f12 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 10
34 CoreFoundation 0x24e51e48 _CFXNotificationPost + 1796
35 Foundation 0x25b86e5c -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
36 UIKit 0x28a44b94 -[UIInputWindowController postStartNotifications:withInfo:] + 412
37 UIKit 0x28a45fb4 __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke579 + 396
38 UIKit 0x28413d22 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 474
39 UIKit 0x284d579e +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 62
40 UIKit 0x284a093a -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 166
41 UIKit 0x28a45d18 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 828
42 UIKit 0x28a49584 -[UIInputWindowController setPlacement:starting:completion:] + 44
43 UIKit 0x28a4913a -[UIInputWindowController setInputViewSet:] + 610
44 UIKit 0x28a457aa -[UIInputWindowController performOperations:withAnimationStyle:] + 38
45 UIKit 0x28498102 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1010
46 UIKit 0x2845b7f0 -[UIResponder becomeFirstResponder] + 404
47 UIKit 0x2845bab6 -[UIView(Hierarchy) becomeFirstResponder] + 102
48 UIKit 0x2857ab6a -[UITextView becomeFirstResponder] + 70
49 UIKit 0x2857aa6a -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 170
50 UIKit 0x2857a36a -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 1994
51 UIKit 0x285601aa _UIGestureRecognizerSendActions + 290
52 UIKit 0x2840ec98 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 664
53 UIKit 0x28823a8c ___UIGestureRecognizerUpdate_block_invoke661 + 44
54 UIKit 0x283d8512 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 214
55 UIKit 0x283d648a _UIGestureRecognizerUpdate + 2946
56 UIKit 0x2840d088 -[UIWindow _sendGesturesForEvent:] + 780
57 UIKit 0x2840c958 -[UIWindow sendEvent:] + 516
58 UIKit 0x283e30e0 -[UIApplication sendEvent:] + 192
59 My App 0x0023e95a 0x28000 + 2189658
60 UIKit 0x28656b9e _UIApplicationHandleEventFromQueueEvent + 13870
61 UIKit 0x283e1b22 _UIApplicationHandleEventQueue + 1290
62 CoreFoundation 0x24f04fd4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
63 CoreFoundation 0x24f043e6 __CFRunLoopDoSources0 + 218
64 CoreFoundation 0x24f02a64 __CFRunLoopRun + 764
65 CoreFoundation 0x24e4fb2c CFRunLoopRunSpecific + 472
66 CoreFoundation 0x24e4f93e CFRunLoopRunInMode + 102
67 GraphicsServices 0x2c1d504c GSEventRunModal + 132
68 UIKit 0x28441f1c UIApplicationMain + 1436
69 My App 0x0002e56e 0x28000 + 25966
70 My App 0x0002e4f4 0x28000 + 25844

Posting my solution if anyone faces same issue.
The TextView was in an view controller which was presented modally using UIModalPresentationFormSheet presentation style. After I changed to UIModalPresentationPageSheet it worked fine. This means the Form sheet caused some problem while popping up the keyboard.

Related

Crash viewDidMoveToWindow:shouldAppearOrDisappear: on iOS 10

Since a while my app crashes in production but It has been impossible to reproduce this error in debug mode.
The error in Crashlytics is:
UIKit
-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]
SIGABRT ABORT 0x00000001825d4d74
Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x1825d4d74 __abort_with_payload + 8
1 libsystem_kernel.dylib 0x1825d1480 abort_with_payload_wrapper_internal + 100
2 libsystem_kernel.dylib 0x1825d141c abort_with_payload_wrapper_internal + 34
3 libobjc.A.dylib 0x18203fed8 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 112
4 libobjc.A.dylib 0x18203fe30 __objc_error + 42
5 libobjc.A.dylib 0x182052cd4 weak_entry_insert(weak_table_t*, weak_entry_t*) + 318
6 libobjc.A.dylib 0x182058664 objc_initWeak + 324
7 UIKit 0x1894ce1bc -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 2068
8 UIKit 0x18944db5c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1352
9 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
10 UIKit 0x189471714 -[UIScrollView _didMoveFromWindow:toWindow:] + 92
11 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
12 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
13 UIKit 0x189471714 -[UIScrollView _didMoveFromWindow:toWindow:] + 92
14 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
15 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
16 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
17 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
18 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
19 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
20 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
21 UIKit 0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
22 UIKit 0x18944cd90 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 156
23 Foundation 0x184034510 -[NSISEngine withBehaviors:performModifications:] + 168
24 UIKit 0x18944cc04 -[UIView(Hierarchy) _postMovedFromSuperview:] + 820
25 UIKit 0x18974a078 __UIViewWasRemovedFromSuperview + 172
26 UIKit 0x18944bc80 -[UIView(Hierarchy) removeFromSuperview] + 512
27 UIKit 0x1897a23dc __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.629 + 1044
28 UIKit 0x18979c4fc -[UIPresentationController transitionDidFinish:] + 124
29 UIKit 0x18990afc8 -[_UICurrentContextPresentationController transitionDidFinish:] + 40
30 UIKit 0x1897a012c __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 188
31 UIKit 0x189578ad4 -[_UIViewControllerTransitionContext completeTransition:] + 116
32 UIKit 0x1895788c0 -[UITransitionView notifyDidCompleteTransition:] + 252
33 UIKit 0x1895783dc -[UITransitionView _didCompleteTransition:] + 1240
34 UIKit 0x189577ef0 -[UITransitionView _transitionDidStop:finished:] + 124
35 UIKit 0x189489b48 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312
36 UIKit 0x189489988 -[UIViewAnimationState animationDidStop:finished:] + 160
37 QuartzCore 0x186912404 CA::Layer::run_animation_callbacks(void*) + 260
38 libdispatch.dylib 0x1824911c0 _dispatch_client_callout + 16
39 libdispatch.dylib 0x182495d6c _dispatch_main_queue_callback_4CF + 1000
40 CoreFoundation 0x1835b5f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
41 CoreFoundation 0x1835b3b18 __CFRunLoopRun + 1660
42 CoreFoundation 0x1834e2048 CFRunLoopRunSpecific + 444
43 GraphicsServices 0x184f65198 GSEventRunModal + 180
44 UIKit 0x1894bc628 -[UIApplication _run] + 684
45 UIKit 0x1894b7360 UIApplicationMain + 208
46 <App Name> 0x100081590 main (main.m:14)
47 libdispatch.dylib 0x1824c45b8 (Missing)
Most of the logs show that the user had between 1% and 3% of RAM memory free but there are some with more than 10%.
Also my app tracks errors using Sentry but this error is not in Sentry only in Fabric.
Most of my users use iOS 10 but still there are who use iOS 9 and this crash seems that not affect these users. So it seems it is related to iOS 10.
Also I have searched here but I have not could find a solution even a clue. Someone could help me to find a clue?
EDIT
Regarding the comments the new code introduced that it is related with UIViewController is:
- (IBAction)tapClose:(id)sender {
[self close];
}
- (void)close {
_dismissing = YES;
CGFloat height = self.view.superview.frame.size.height;
[UIView animateWithDuration:0.2 animations:^{
[self.view setFrame:CGRectMake(0, height, self.view.frame.size.width, self.view.frame.size.height)];
_overlay.alpha = 0;
} completion:^(BOOL finished) {
if (finished) {
[self.view removeFromSuperview];
[_overlay removeFromSuperview];
if (self.blockWhenClose) {
self.blockWhenClose();
}
}
}];
}
- (void)showIn:(UIViewController *)viewcontroller {
CGRect frame = viewcontroller.view.frame;
CGFloat height = [self calculateHeight:frame.size.height / 2];
[self.view setFrame:CGRectMake(0, frame.size.height, frame.size.width, height)];
[_overlay setFrame:frame];
_overlay.alpha = 0;
[viewcontroller addChildViewController:self];
[viewcontroller.view addSubview:_overlay];
[viewcontroller.view addSubview:self.view];
[self didMoveToParentViewController:viewcontroller];
[UIView animateWithDuration:_duration animations:^{
_overlay.alpha = 1;
[self.view setFrame:CGRectMake(0, frame.size.height - height, frame.size.width, height)];
}];
_show = YES;
}
But I do not know where exactly the crash occurs.
For me this started with iOS 14
The problem was, I had code where the view of a controller (A) was added as a subview to another controller(B) without holding a reference to the controller(A) itself. the controller(A) was deallocated and next time the view is about to appear or disappear, it tries to notify the controller(A) which causes a crashes.
Solution:
Manually hold a reference to the controller
OR addChildViewController which does the above for you

SpriteKit crash on transitionWithView

I have several crash reports with Collection <__NSArrayM: 0x12345678> was mutated while being enumerated. However in my testing I cannot reproduce the error.
This seems be triggered via a chain of events when I transition to a different SKView.
[UIView transitionWithView:window
duration:0.8
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[UIView setAnimationsEnabled:NO];
[fromView removeFromSuperview];
[window addSubview:toView];
window.rootViewController = nextViewController;
[UIView setAnimationsEnabled:YES];
}
completion:NULL];
I have read that this error can happen when you remove nodes from their parent during enumeration of child nodes but I don't believe I am doing this here, and the full stack trace below doesn't seem to indicate it either.
I don't know why [SKNode setPaused:] would cause child nodes to be added or removed, and there doesn't appear to be any indication of this happening in other threads either.
Full Stacktrace
0 CoreFoundation 0x2f896fd3 __exceptionPreprocess + 131
1 libobjc.A.dylib 0x3a37bccf objc_exception_throw + 36
2 CoreFoundation 0x2f896ad1 __NSFastEnumerationMutationHandler + 126
3 SpriteKit 0x31fb926b -[SKNode setPaused:] + 792
4 SpriteKit 0x31f95309 -[SKScene setPaused:] + 134
5 SpriteKit 0x31fa7b63 -[SKView renderCallback:] + 648
6 SpriteKit 0x31fa9301 -[SKView layoutSubviews] + 474
7 UIKit 0x320b2d79 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 378
8 QuartzCore 0x31d3062b -[CALayer layoutSublayers] + 140
9 QuartzCore 0x31d2be3b _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 348
10 QuartzCore 0x31d5acdd -[CALayer layoutIfNeeded] + 138
11 UIKit 0x3212f183 -[UIViewController window:setupWithInterfaceOrientation:] + 240
12 UIKit 0x3212d7a3 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 3496
13 UIKit 0x3212c9f3 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 44
14 UIKit 0x3212c97b -[UIWindow _setRotatableViewOrientation:updateStatusBar:duration:force:] + 92
15 UIKit 0x3212c913 -[UIWindow _setRotatableViewOrientation:duration:force:] + 40
16 UIKit 0x32124f89 __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke + 106
17 UIKit 0x320b9127 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 380
18 UIKit 0x3212c661 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 694
19 UIKit 0x3212c125 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 162
20 UIKit 0x320be065 -[UIWindow addRootViewControllerViewIfPossible] + 458
21 UIKit 0x32124133 -[UIWindow setRootViewController:] + 760
22 the-app 0x000baf0d 0x000b2000 + 36621
23 UIKit 0x320e83c5 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 494
24 UIKit 0x3234c3f9 +[UIView(UIViewAnimationWithBlocks) transitionWithView:duration:options:animations:completion:] + 58
25 the-app 0x000bae67 0x000b2000 + 36455
26 the-app 0x000bacf7 0x000b2000 + 36087
27 UIKit 0x320e8057 -[UIApplication sendAction:to:from:forEvent:] + 88
28 UIKit 0x320e7ff7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 28
29 UIKit 0x320e7fd1 -[UIControl sendAction:to:forEvent:] + 42
30 UIKit 0x320d3737 -[UIControl _sendActionsForEvents:withEvent:] + 372
31 UIKit 0x320e7a4f -[UIControl touchesEnded:withEvent:] + 588
32 UIKit 0x320e7721 -[UIWindow _sendTouchesForEvent:] + 526
33 UIKit 0x320e26eb -[UIWindow sendEvent:] + 756
34 UIKit 0x320b78ed -[UIApplication sendEvent:] + 194
35 UIKit 0x320b5f97 _UIApplicationHandleEventQueue + 7100
36 CoreFoundation 0x2f86225b __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
37 CoreFoundation 0x2f86172b __CFRunLoopDoSources0 + 204
38 CoreFoundation 0x2f85ff1f __CFRunLoopRun + 620
39 CoreFoundation 0x2f7caf0f CFRunLoopRunSpecific + 520
40 CoreFoundation 0x2f7cacf3 CFRunLoopRunInMode + 104
41 GraphicsServices 0x346c4663 GSEventRunModal + 136
42 UIKit 0x3211616d UIApplicationMain + 1134
43 the-app 0x000b9267 0x000b2000 + 29287
44 libdyld.dylib 0x3a888ab7 start + 0

When dismissing keyboard how do I keep my existing text fields in the same location?

So I have a UIScrollView that contains UITextFields and UILabels, and when the user clicks inside a UITextField the keyboard shows. But I need a way to allow the user to dismiss the keyboard and I was try to use the swipe down gesture to do it (as in Messages). I added the Gesture Recognizer to my view in the storyboard and added the Action to the header file. Here is the method:
- (IBAction)SwipeKeyboardDown:(id)sender
{
if(self.moveTextField)
{
[self.moveTextField resignFirstResponder];
}
}
I just have the if there for testing when a user has clicked on the first text field, and when they try to swipe down all of the text field and labels move to the bottom of the screen. Is there anything I need to do to keep the text fields and labels in their place? I am using Auto Layout and I created them all in the storyboard.
This is how my view looks before swiping the keyboard down:
And this is how it looks after swiping down:
Thanks for the help, and if more info is needed please ask and I can provide more.
Backtrace:
2014-02-02 01:28:33.453 BJJDrillingAppPro[512:70b] (
0 BJJDrillingAppPro 0x0001de82 -[AddMoveViewControllerPro observeValueForKeyPath:ofObject:change:context:] + 210
1 Foundation 0x0116e8c7 NSKeyValueNotifyObserver + 362
2 Foundation 0x01170206 NSKeyValueDidChange + 458
3 Foundation 0x0112c8dd -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 120
4 Foundation 0x010ffcc7 _NSSetPointValueAndNotify + 185
5 UIKit 0x00320cae -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 2622
6 UIKit 0x0030384d -[UIScrollView setContentSize:] + 354
7 BJJDrillingAppPro 0x0002023d -[AddMoveViewControllerPro keyboardDidHide] + 493
8 Foundation 0x011f2bf9 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
9 CoreFoundation 0x017f8524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
10 CoreFoundation 0x0175000b _CFXNotificationPost + 2859
11 Foundation 0x0112c951 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
12 UIKit 0x0071d6f5 -[UIInputViewTransition postNotificationsForTransitionStart] + 1004
13 UIKit 0x007137e2 -[UIPeripheralHost(UIKitInternal) executeTransition:] + 592
14 UIKit 0x00715c0e -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1029
15 UIKit 0x00716019 -[UIPeripheralHost(UIKitInternal) setInputViews:animated:] + 72
16 UIKit 0x00716063 -[UIPeripheralHost(UIKitInternal) setInputViews:] + 67
17 UIKit 0x0070d2fa -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 1453
18 UIKit 0x003e707c -[UIResponder _finishResignFirstResponder] + 163
19 UIKit 0x003e719f -[UIResponder resignFirstResponder] + 265
20 UIKit 0x0096b5f4 -[UITextField resignFirstResponder] + 118
21 BJJDrillingAppPro 0x0001dd70 -[AddMoveViewControllerPro SwipeKeyboardDown:] + 288
22 UIKit 0x00605e8c _UIGestureRecognizerSendActions + 230
23 UIKit 0x00604b00 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 383
24 UIKit 0x0060656d -[UIGestureRecognizer _delayedUpdateGesture] + 60
25 UIKit 0x00609acd ___UIGestureRecognizerUpdate_block_invoke + 57
26 UIKit 0x00609a4e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 317
27 UIKit 0x00600148 _UIGestureRecognizerUpdate + 199
28 UIKit 0x002cc19a -[UIWindow _sendGesturesForEvent:] + 1291
29 UIKit 0x002cd0ba -[UIWindow sendEvent:] + 1030
30 UIKit 0x002a0e86 -[UIApplication sendEvent:] + 242
31 UIKit 0x0028b18f _UIApplicationHandleEventQueue + 11421
32 CoreFoundation 0x0172583f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
33 CoreFoundation 0x017251cb __CFRunLoopDoSources0 + 235
34 CoreFoundation 0x0174229e __CFRunLoopRun + 910
35 CoreFoundation 0x01741ac3 CFRunLoopRunSpecific + 467
36 CoreFoundation 0x017418db CFRunLoopRunInMode + 123
37 GraphicsServices 0x03aa39e2 GSEventRunModal + 192
38 GraphicsServices 0x03aa3809 GSEventRun + 104
39 UIKit 0x0028dd3b UIApplicationMain + 1225
40 BJJDrillingAppPro 0x0001bf0d main + 141
41 libdyld.dylib 0x0213c70d start + 1
42 ??? 0x00000001 0x0 + 1
)
And after looking at my code for the keyboard did show and hide methods I am wondering if maybe I am doing something wrong there:
This is in my viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidHide)
name:UIKeyboardWillHideNotification
object:nil];
And these are the selectors:
- (void)keyboardDidHide
{
if(keyboardShown)
{
CGRect r = self.scrollView.frame;
r.size.height += 216;
self.scrollView.frame = r;
keyboardShown = NO;
}
}
- (void)keyboardDidShow
{
if(!keyboardShown)
{
CGRect r = self.scrollView.frame;
self.scrollView.contentSize = self.scrollView.frame.size;
r.size.height -= 216;
self.scrollView.frame = r;
keyboardShown = YES;
}
}
You don't need a gesture recognizer.
Scrollviews have the keyboardDismissMode property. Set it to UIScrollViewKeyboardDismissModeOnDrag or UIScrollViewKeyboardDismissModeInteractive and you are set to go.

UITabBarCrashes only when tabs are in a specific order

I have a UITabBarController with three views. When I select View#2 the application crashes (see crash log). If I reorder the tabs so that View#2 is first it works (No crash).
0 libobjc.A.dylib 0x3368ef78 objc_msgSend + 16
1 CoreFoundation 0x359b8e90 CFRetain + 76
2 CoreFoundation 0x359c2b74 +[__NSArrayI __new::] + 48
3 CoreFoundation 0x359c2a8e -[__NSPlaceholderArray initWithObjects:count:] + 294
4 CoreFoundation 0x359c27ce +[NSArray arrayWithObjects:count:] + 38
5 CoreFoundation 0x359c24f2 -[NSDictionary allValues] + 230
6 UIKit 0x333e7f46 -[UINib instantiateWithOwner:options:] + 538
7 UIKit 0x333563c0 -[UIViewController _loadViewFromNibNamed:bundle:] + 240
8 UIKit 0x33233c52 -[UIViewController loadView] + 82
9 UIKit 0x331a9c10 -[UIViewController view] + 44
10 UIKit 0x33209636 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 86
11 UIKit 0x332095d4 -[UITabBarController transitionFromViewController:toViewController:] + 24
12 UIKit 0x33208f0e -[UITabBarController _setSelectedViewController:] + 294
13 UIKit 0x3329244e -[UITabBarController _tabBarItemClicked:] + 338
14 CoreFoundation 0x359ca3f6 -[NSObject performSelector:withObject:withObject:] + 46
15 UIKit 0x3318be00 -[UIApplication sendAction:to:from:forEvent:] + 56
16 UIKit 0x3318bdbc -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
17 UIKit 0x332922d2 -[UITabBar _sendAction:withEvent:] + 346
18 CoreFoundation 0x359ca3f6 -[NSObject performSelector:withObject:withObject:] + 46
19 UIKit 0x3318be00 -[UIApplication sendAction:to:from:forEvent:] + 56
20 UIKit 0x3318bdbc -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
21 UIKit 0x3318bd9a -[UIControl sendAction:to:forEvent:] + 38
22 UIKit 0x3318bb0a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
23 UIKit 0x33292062 -[UITabBar(Static) _buttonUp:] + 110
24 CoreFoundation 0x359ca3f6 -[NSObject performSelector:withObject:withObject:] + 46
25 UIKit 0x3318be00 -[UIApplication sendAction:to:from:forEvent:] + 56
26 UIKit 0x3318bdbc -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
27 UIKit 0x3318bd9a -[UIControl sendAction:to:forEvent:] + 38
28 UIKit 0x3318bb0a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
29 UIKit 0x3318c442 -[UIControl touchesEnded:withEvent:] + 470
30 UIKit 0x3318a924 -[UIWindow _sendTouchesForEvent:] + 312
31 UIKit 0x3318a312 -[UIWindow sendEvent:] + 374
32 UIKit 0x3317068e -[UIApplication sendEvent:] + 350
33 UIKit 0x3316ff34 _UIApplicationHandleEvent + 5820
34 GraphicsServices 0x33762224 PurpleEventCallback + 876
35 CoreFoundation 0x35a4451c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
36 CoreFoundation 0x35a444be __CFRunLoopDoSource1 + 134
37 CoreFoundation 0x35a4330c __CFRunLoopRun + 1364
38 CoreFoundation 0x359c649e CFRunLoopRunSpecific + 294
39 CoreFoundation 0x359c6366 CFRunLoopRunInMode + 98
40 GraphicsServices 0x33761432 GSEventRunModal + 130
41 UIKit 0x3319ecce UIApplicationMain + 1074
42 TecNotes 0x000c2a28 main (main.m:18)
43 TecNotes 0x000c2940 start + 32
There is no custom class or instance initialization. And the viewDidLoad method of View#2 does not seem to execute.
In an effort to debug the issue the viewDidLoad for View#2 has been reduced to the following.
- (void)viewDidLoad
{
NSLog(#"Enter View#2 viewDidLoad");
[super viewDidLoad];
NSLog(#"Exit View#2 viewDidLoad");
}
View#1 has similar logging to record that the viewDidLoad method is called.
- (void)viewDidLoad
{
NSLog(#"Enter View#1 viewDidLoad");
[super viewDidLoad];
NSFileManager *filemgr = [NSFileManager defaultManager];
NSString *cd = [filemgr currentDirectoryPath];
recipeName = [cd lastPathComponent];
NSString *basedir = [CategoryViewController getBaseDir];
int startPos = [basedir length]+1;
int len = [cd length]-startPos;
NSString *tmp = [cd substringWithRange:NSMakeRange(startPos, len)];
title = [CategoryViewController decode:tmp];
//self.navigationItem.backBarButtonItem.title = recipeName;
//self.tabBarController.navigationItem.title = recipeName;
currentNote = 0;
//-------
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipedScreen:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeGesture];
swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipedScreen:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft ;
[self.view addGestureRecognizer:swipeGesture];
//-------
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:#"Menu" style:UIBarButtonItemStylePlain target:self action:#selector(backButtonPressed)];
self.navigationItem.backBarButtonItem = back;
self.tabBarController.navigationItem.backBarButtonItem = back;
[noteView setFont:[UIFont systemFontOfSize:[NotesViewController getFontSize]]];
[self loadNotes];
NSLog(#"Exit View#1 viewDidLoad");
}
Here is the resulting log entries.
Dec 16 11:42:21 Tonys-iPad TecNotes[6577] : Enter View#1 viewDidLoad
Dec 16 11:42:21 Tonys-iPad TecNotes[6577] : Exit View#1 viewDidLoad
Dec 16 11:42:27 Tonys-iPad ReportCrash[6580] : Formulating crash report for process TecNotes[6577]
Dec 16 11:42:27 Tonys-iPad com.apple.launchd[1] (UIKitApplication:com.bringardner.tecnotes[0x2bd8][6577]) : (UIKitApplication:com.bringardner.tecnotes[0x2bd8]) Job appears to have crashed: Segmentation fault: 11

Crash when installing the app on ipad, works fine in simulator

I am gettting the below issue in my application (Pls help me):
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [1.07157e-08 nan]'
*** Call stack at first throw:
(
0 CoreFoundation 0x3126a64f __exceptionPreprocess + 114
1 libobjc.A.dylib 0x32b12c5d objc_exception_throw + 24
2 CoreFoundation 0x3126a491 +[NSException raise:format:arguments:] + 68
3 CoreFoundation 0x3126a4cb +[NSException raise:format:] + 34
4 QuartzCore 0x32c6f61d _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 140
5 QuartzCore 0x32c6f58b -[CALayer setPosition:] + 38
6 QuartzCore 0x32c6f4d7 -[CALayer setFrame:] + 390
7 UIKit 0x35a31455 -[UIView(Geometry) setFrame:] + 188
8 UIKit 0x35a51743 UIViewCommonInitWithFrame + 594
9 UIKit 0x35a514a1 -[UIView initWithFrame:] + 84
10 CaCaCard 0x0000683b -[CaCaCardsAppViewController shouldAutorotateToInterfaceOrientation:] + 510
11 UIKit 0x35a6eead -[UIViewController _isSupportedInterfaceOrientation:] + 48
12 UIKit 0x35a6ee6f -[UINavigationController _doesTopViewControllerSupportInterfaceOrientation:] + 46
13 UIKit 0x35a6ee37 -[UINavigationController shouldAutorotateToInterfaceOrientation:] + 14
14 UIKit 0x35a6edbf -[UINavigationController _isSupportedInterfaceOrientation:] + 54
15 UIKit 0x35a6fbbb -[UIViewController window:shouldAutorotateToInterfaceOrientation:] + 46
16 UIKit 0x35a6f857 -[UIWindow _shouldAutorotateToInterfaceOrientation:] + 194
17 UIKit 0x35a6f4a3 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 366
18 UIKit 0x35a6f0ad -[UIWindow setDelegate:] + 168
19 UIKit 0x35a6efa9 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 64
20 UIKit 0x35a6d611 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 460
21 UIKit 0x35a6d3e5 -[UINavigationController viewDidMoveToWindow:shouldAppearOrDisappear:] + 36
22 UIKit 0x35a4c5a7 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 506
23 UIKit 0x35a4c32f -[UIView(Hierarchy) _postMovedFromSuperview:] + 106
24 UIKit 0x35a31c1b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 678
25 UIKit 0x35a3196b -[UIView(Hierarchy) addSubview:] + 22
26 CaCaCard 0x00004bcf -[CaCaCardsAppAppDelegate application:didFinishLaunchingWithOptions:] + 318
27 UIKit 0x35a61821 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 772
28 UIKit 0x35a5bb65 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 272
29 UIKit 0x35a307d7 -[UIApplication handleEvent:withNewEvent:] + 1114
30 UIKit 0x35a30215 -[UIApplication sendEvent:] + 44
31 UIKit 0x35a2fc53 _UIApplicationHandleEvent + 5090
32 GraphicsServices 0x31d37e77 PurpleEventCallback + 666
33 CoreFoundation 0x31241a97 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
34 CoreFoundation 0x3124383f __CFRunLoopDoSource1 + 166
35 CoreFoundation 0x3124460d __CFRunLoopRun + 520
36 CoreFoundation 0x311d4ec3 CFRunLoopRunSpecific + 230
37 CoreFoundation 0x311d4dcb CFRunLoopRunInMode + 58
38 UIKit 0x35a5ad49 -[UIApplication _run] + 372
39 UIKit 0x35a58807 UIApplicationMain + 670
40 CaCaCard 0x000028e7 main + 70
41 CaCaCard 0x0000289c start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
warning: Unable to read symbols for /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.3.5 (8L1)/Symbols/Developer/usr/lib/libXcod
eDebuggerSupport.dylib (file not found).
(gdb)
-(void) viewWillAppear:(BOOL)animated
//-----------------------------------
{
if ( self.interfaceOrientation == UIInterfaceOrientationPortrait ||
self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
{
[NSThread sleepForTimeInterval:0.5];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[[UIApplication sharedApplication] setStatusBarOrientation:
UIInterfaceOrientationLandscapeRight];
UIScreen *screen = [UIScreen mainScreen];
CGFloat screenWidth = screen.bounds.size.width;
CGFloat screenHeight = screen.bounds.size.height;
UIView *navView = [[self navigationController] view];
navView.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
navView.transform = CGAffineTransformIdentity;
navView.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
navView.center = CGPointMake(screenWidth/2.0, screenHeight/2.0);
[UIView commitAnimations];
}
fontSelected = NO;
}
The problem is an invalid frame size you are setting at some point. Probably a rect with a zero value somewhere.
From your code I would suspect you are getting some unexpected values back when you are asking for the screen size.
Also don't use those old animation functions. Use the block based animation. It's much better.

Resources