An UIButton is contained inside a UIScrollView. I have this setup in a xib. I use a NSLayoutConstraint to change the height of the scrollview. After I click the button, the scrollview changes height, but then UIButton becomes unclickable.
Here is the code:
- (IBAction)TagPressed:(UIButton *)sender {
if (self.height.constant == 200) {
self.height.constant = 88;
}else
self.height.constant = 200;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
DRect(_scrollView.frame)
DRect(self.view.frame)
DRect(sender.frame)
NSLog(sender.selected ? #"Selected" : #"Not Selected");
}
Drect is a nslog for frames. So the Console out is:
2013-04-08 17:04:19.264 TouchSelectApp[93618:c07] CGRect ( 20.000000, -112.000000, 62.000000, 200.000000)
2013-04-08 17:04:19.266 TouchSelectApp[93618:c07] CGRect ( 0.000000, 300.000000, 320.000000, 88.000000)
2013-04-08 17:04:19.266 TouchSelectApp[93618:c07] CGRect ( 7.000000, 78.500000, 48.000000, 44.000000)
Output from (lldb) po [[UIApp keyWindow] recursiveDescription]
I had to add a an extra button to create a debugging stop. The button I care about is inside SelectableTag.
$0 = 0x0887e0e0 <UIWindow: 0x7197a90; frame = (0 0; 320 568); autoresize = W+H; layer = <UIWindowLayer: 0x7199620>>
| <UIView: 0x719ed20; frame = (0 20; 320 548); autoresize = W+H; layer = <CALayer: 0x719edd0>>
| | <UIRoundedRectButton: 0x719b9d0; frame = (51 464; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x719baf0>>
| | | <UIGroupTableViewCellBackground: 0x719c2a0; frame = (0 0; 73 44); userInteractionEnabled = NO; layer = <CALayer: 0x719c370>>
| | | <UIImageView: 0x719da50; frame = (1 1; 71 43); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x719dd20>>
| | | <UIButtonLabel: 0x719d0f0; frame = (12 12; 49 19); text = 'Button'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x719d1e0>>
| | <UIView: 0x71a1160; frame = (0 300; 320 88); autoresize = RM+BM; layer = <CALayer: 0x71a11c0>>
| | | <SelectableTag: 0x719fcc0; baseClass = UIScrollView; frame = (20 -112; 62 200); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x71a04e0>; layer = <CALayer: 0x719fef0>; contentOffset: {0, 0}>
| | | | <UIImageView: 0x71a0c20; frame = (55 193; 7 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x71a0cc0>>
| | | | <UIImageView: 0x71a0dd0; frame = (55 62; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x71a0e70>>
| | | | <UIRoundedRectButton: 0x719ddd0; frame = (-1 7; 64 44); opaque = NO; layer = <CALayer: 0x719b630>>
| | | | | <UIGroupTableViewCellBackground: 0x719d630; frame = (0 0; 64 44); userInteractionEnabled = NO; layer = <CALayer: 0x719b690>>
| | | | | <UIImageView: 0x719dea0; frame = (1 1; 62 43); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x719d990>>
| | | | | <UIButtonLabel: 0x71a1630; frame = (12 12; 40 19); text = 'Test1'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x71a1e50>>
(lldb)
From the documentation of hitTest:withEvent: in the UIView Class Reference:
Points that lie outside the receiver’s bounds are never reported as hits, even if they actually lie within one of the receiver’s subviews. This can occur if the current view’s clipsToBounds property is set to NO and the affected subview extends beyond the view’s bounds.
The parent of your scroll view is the view with address 0x71a1160. Notice that the scroll view's frame.origin.y is -112. So the top 112 points of the scroll view are outside of its parent's bounds. That part of the scroll view will never receive touches. Your Test1 button is entirely in that part of the scroll view.
I have noticed this behavior too with UIButtons. After changing the frame of the parent view, if you add the button again it will work.
Related
I'm in my SKScene and I want to unhide a text field in the presenting view controller. I'm using NSNotificationCenter to call a function in my view controller and I've even seen the code arrive at the function and pass the line where the textfield is unhidden, but for some strange reason it doesn't appear. Any thoughts?
Here is the output from the lldb:
<UIWindow: 0x7bf3dbb0; frame = (0 0; 320 568); autoresize = W+H; gestureRecognizers = <NSArray: 0x7bf4dd60>; layer = <UIWindowLayer: 0x7bf364c0>>
| <UITransitionView: 0x833c34e0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x833c3720>>
| | <SKView: 0x7c86de00; frame = (0 0; 320 568); autoresize = W+H; autoresizesSubviews = NO; gestureRecognizers = <NSArray: 0x7d48e4c0>; layer = <CAEAGLLayer: 0x7bf38d20>>
| | | <UIButton: 0x7bf475f0; frame = (227 458; 64 90); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7bf47120>>
| | | | <UIImageView: 0x837dca00; frame = (0 0; 64 90); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x837dcae0>> - (null)
| | | | <UIButtonLabel: 0x837dcbf0; frame = (18 39.5; 28.5 13.5); text = 'Store'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x837dcd00>>
| | | <OptionMenu: 0x7bf3b300; frame = (43 55; 114 493); hidden = YES; autoresize = RM+BM; layer = <CALayer: 0x7bf3b530>>
| | | | <UIView: 0x7bf2c1c0; frame = (0 0; 600 600); autoresize = RM+BM; layer = <CALayer: 0x7bf2c560>>
| | | | | <UIImageView: 0x7d433820; frame = (0 0; 600 600); autoresize = RM+BM; tag = 1; layer = <CALayer: 0x7d42a2c0>> - (null)
| | | | | <UILabel: 0x7bf2b0f0; frame = (38 15; 562 42); text = ''; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7bf2c280>>
| | | | | <UILabel: 0x7d43b1f0; frame = (49 88; 321 334); text = 'Dear Samuel,
I'll be spe...'; opaque = NO; autoresize = RM+BM; layer = <_UILabelLayer: 0x7d43a6e0>>
| | | | | <UIButton: 0x7bf2e790; frame = (31 15; 50 50); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7bf3c120>>
| | | | | | <UIImageView: 0x837dc5e0; frame = (0 0; 50 50); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x837dc6c0>> - (null)
| | | <_UILayoutGuide: 0x7bf3bf50; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7bf645c0>>
| | | <_UILayoutGuide: 0x7bf3bb30; frame = (0 568; 0 0); hidden = YES; layer = <CALayer: 0x7bf29910>>
| | | <UITextField: 0x833bf810; frame = (20 150; 280 31); text = ''; clipsToBounds = YES; alpha = 0; opaque = NO; tag = 2; gestureRecognizers = <NSArray: 0x83470100>; layer = <CALayer: 0x833bfb10>>
| | | | <_UITextFieldRoundedRectBackgroundViewNeue: 0x833c19f0; frame = (0 0; 280 31); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x833c1bf0>> - (null)
| | | | <UITextFieldLabel: 0x833c1220; frame = (7 2; 266 27); text = 'Password'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x833c1330>>
I'm having problems tracking down some conflicting constraints. The AutoresizingMask has been added for me, and the other constraint I added in an attempt to understand what is going on:
2015-09-26 22:27:14.959 Darkenss[26537:8462681] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>",
"<NSAutoresizingMaskLayoutConstraint:0x7fc461d3f820 h=--- v=--- 'UIView-Encapsulated-Layout-Top' V:[UIView:0x7fc461fc6620]-(0)-|>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>
I don't see how these two constraints are actually in conflict.
The view hierarchy is:
<UIView: 0x7fc461fc6620; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7fc461fc48a0>>
| <UIImageView: 0x7fc461fd4f50; frame = (0 0; 600 600); clipsToBounds = YES; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fc7ea0>>
| <UILabel: 0x7fc461fcba20; frame = (28 68; 300 48); text = 'Darkness AP'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461fcb910>>
| <Darkenss.UIDescreteSliderWithCircles: 0x7fc461e477c0; frame = (28 124; 544 30); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2df00>; layer = <CALayer: 0x7fc461fb09b0>>
| <UIButton: 0x7fc461e8c8e0; frame = (28 162; 93 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2c770>; layer = <CALayer: 0x7fc461e99bb0>>
| | <UIImageView: 0x7fc461d2ad70; frame = (0 6.5; 93 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d2af10>>
| <UIButton: 0x7fc461e1ee60; frame = (129 162; 92 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2ccd0>; layer = <CALayer: 0x7fc461e1beb0>>
| | <UIImageView: 0x7fc461d38d50; frame = (0 6.5; 92 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d38ef0>>
| <UIButton: 0x7fc461e20c10; frame = (229 162; 93 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2d1f0>; layer = <CALayer: 0x7fc461e372b0>>
| | <UIImageView: 0x7fc461d23ab0; frame = (0 6.5; 93 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d23c50>>
| <UIButton: 0x7fc461e04d20; frame = (330 162; 92 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461c2d400>; layer = <CALayer: 0x7fc461e225a0>>
| | <UIImageView: 0x7fc461d2a9a0; frame = (0 6.5; 92 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d43d80>>
| <UIButton: 0x7fc461e31e20; frame = (430 162; 81 128); opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461e99d00>; layer = <CALayer: 0x7fc461e31cd0>>
| | <UIImageView: 0x7fc461d2c750; frame = (0 6.5; 81 115); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d1e660>>
| <UIButton: 0x7fc461e374f0; frame = (16 97.5; 145.5 128); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc461e34cb0>>
| | <UIImageView: 0x7fc461d20da0; frame = (0 0; 145.5 128); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d47ed0>>
| | <UIImageView: 0x7fc461e55d50; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461e3d850>>
| | <UIButtonLabel: 0x7fc461d20f40; frame = (0 55.5; 27.5 17.5); text = 'Run
Darkness
Cycle'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461d212f0>>
| <UIButton: 0x7fc461e2d510; frame = (169.5 97.5; 181.5 128); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc461e60e10>>
| | <UIImageView: 0x7fc461d51e50; frame = (0 0; 181.5 128); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d431f0>>
| | <UIImageView: 0x7fc461d3c3c0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d3c560>>
| | <UIButtonLabel: 0x7fc461d5c0e0; frame = (26.5 55.5; 128.5 17.5); text = ' Continue Combo '; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc461d52250>>
| <UIImageView: 0x7fc461fcda20; frame = (4 302; 592 294); clipsToBounds = YES; hidden = YES; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fcd030>>
| <UICollectionView: 0x7fc463090000; frame = (4 310; 367 353); clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7fc461e45640>; layer = <CALayer: 0x7fc461e3b3a0>; contentOffset: {0, 0}; contentSize: {367, 54}> collection view layout: <UICollectionViewFlowLayout: 0x7fc461e468d0>
| | <Darkenss.AddTrackerViewCell: 0x7fc4640217f0; baseClass = UICollectionViewCell; frame = (0 0; 54 54); layer = <CALayer: 0x7fc464020fc0>>
| | | <UIButton: 0x7fc4640219c0; frame = (4 4; 46 46); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7fc464020e70>>
| | | | <UIImageView: 0x7fc464024140; frame = (0 0; 46 46); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7fc4640200b0>>
| | | <UIView: 0x7fc464022110; frame = (0 0; 54 54); autoresize = W+H; gestureRecognizers = <NSArray: 0x7fc4640228f0>; layer = <CALayer: 0x7fc464022270>>
| | <Darkenss.CounterArrayCellView: 0x7fc464032270; baseClass = UICollectionViewCell; frame = (54.5 0; 258 53); alpha = 0; layer = <CALayer: 0x7fc464032040>>
| | | <UIView: 0x7fc4640324d0; frame = (0 0; 258 53); gestureRecognizers = <NSArray: 0x7fc464032d10>; layer = <CALayer: 0x7fc464032630>>
| | | | <Darkenss.CounterArrayView: 0x7fc464032d40; frame = (0 0; 94 102); layer = <CALayer: 0x7fc464034b60>>
| | | | | <UILabel: 0x7fc464033190; frame = (6 6; 82 0); text = 'Treasure'; hidden = YES; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7fc464033390>>
| | | | | | <_UILabelContentLayer: 0x7fc461d84ee0> (layer)
| | | | | <UICollectionView: 0x7fc46388e800; frame = (6 14; 82 82); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7fc4640340a0>; layer = <CALayer: 0x7fc464033ba0>; contentOffset: {0, 0}; contentSize: {82, 81}> collection view layout: <Darkenss.CounterArrayLayout: 0x7fc464033960>
| | | | | | <Darkenss.DotView: 0x7fc461d7e190; baseClass = UICollectionViewCell; frame = (0 0; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d7e530>>
| | | | | | | <UIView: 0x7fc461d7e550; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d7ed90>; layer = <CALayer: 0x7fc461d7e6b0>>
| | | | | | | | <UIImageView: 0x7fc461d7e370; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d7e510>>
| | | | | | <Darkenss.DotView: 0x7fc461d82250; baseClass = UICollectionViewCell; frame = (42 0; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d821a0>>
| | | | | | | <UIView: 0x7fc461d825d0; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d82e10>; layer = <CALayer: 0x7fc461d82730>>
| | | | | | | | <UIImageView: 0x7fc461d82430; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d821c0>>
| | | | | | <Darkenss.DotView: 0x7fc461d86290; baseClass = UICollectionViewCell; frame = (0 41; 40 40); hidden = YES; layer = <CALayer: 0x7fc461d86610>>
| | | | | | | <UIView: 0x7fc461d86630; frame = (0 0; 40 40); gestureRecognizers = <NSArray: 0x7fc461d86e80>; layer = <CALayer: 0x7fc461d86790>>
| | | | | | | | <UIImageView: 0x7fc461d86470; frame = (0 0; 40 40); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461d86240>>
| | | | | <UIImageView: 0x7fc464032fd0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc464033170>>
| | <Darkenss.SmallCounterTrackerViewCell: 0x7fc461c90870; baseClass = UICollectionViewCell; frame = (0 53; 108 56); clipsToBounds = YES; alpha = 0; opaque = NO; layer = <CALayer: 0x7fc461c8f970>>
| | | <UIView: 0x7fc461c90a70; frame = (0 0; 188 96); gestureRecognizers = <NSArray: 0x7fc461eb1710>; layer = <CALayer: 0x7fc461c8fb30>>
| | | | <UIImageView: 0x7fc461c90bd0; frame = (4 4; 88 88); opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c8fad0>>
| | | | <Darkenss.OffsetLabels: 0x7fc461c90eb0; frame = (96 4; 88 88); autoresize = RM+BM; layer = <CALayer: 0x7fc461ca0570>>
| | | | | <UITextView: 0x7fc462050200; frame = (0 0; 7 14); text = '10'; clipsToBounds = YES; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7fc461c92170>; layer = <CALayer: 0x7fc461c91af0>; contentOffset: {0, 0}; contentSize: {7, 55}>
| | | | | | <<_UITextContainerView: 0x7fc461c92c00; frame = (0 0; 7 55); layer = <_UITextTiledLayer: 0x7fc461c92dd0>> minSize = {0, 0}, maxSize = {1.7976931348623157e+308, 1.7976931348623157e+308}, textContainer = <NSTextContainer: 0x7fc461c918f0 size = (7.000000,340282346638528859811704183484516925440.000000); widthTracksTextView = YES; heightTracksTextView = NO>; exclusionPaths = 0x7fc461c00dc0; lineBreakMode = 0>
| | | | | | | <UITextSelectionView: 0x7fc461c95070; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c94fb0>>
| | | | | <UITextView: 0x7fc462052000; frame = (0 0; 9 14); text = '10'; clipsToBounds = YES; userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x7fc461c99480>; layer = <CALayer: 0x7fc461c98df0>; contentOffset: {0, 0}; contentSize: {9, 55}>
| | | | | | <<_UITextContainerView: 0x7fc461c9a270; frame = (0 0; 9 55); layer = <_UITextTiledLayer: 0x7fc461c9a440>> minSize = {0, 0}, maxSize = {1.7976931348623157e+308, 1.7976931348623157e+308}, textContainer = <NSTextContainer: 0x7fc461c98bd0 size = (9.000000,340282346638528859811704183484516925440.000000); widthTracksTextView = YES; heightTracksTextView = NO>; exclusionPaths = 0x7fc461c00dc0; lineBreakMode = 0>
| | | | | | | <UITextSelectionView: 0x7fc461c9c750; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x7fc461c9c690>>
| | | | | <CAShapeLayer: 0x7fc461d7d7a0> (layer)
| | <UIImageView: 0x7fc461e44520; frame = (361.5 284; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461e3f7f0>>
| <UIImageView: 0x7fc461fd19f0; frame = (3 292; 286 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fd00c0>>
| <UIImageView: 0x7fc461fdbec0; frame = (289 292; 23 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fdb6e0>>
| <UIImageView: 0x7fc461fe1540; frame = (312 292; 285 21); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7fc461fd1b90>>
| <_UILayoutGuide: 0x7fc461fe6260; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fc461fe5f50>>
| <_UILayoutGuide: 0x7fc461fe6cb0; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7fc461fe5aa0>>
Update: I lost the hard drive that project was living on (but I have a backup that was only 45min old, so it'll all work out when I get a replacement...right? I have hope at least). However I have a very big clue.
I was calculating constraints and triggering layout in a KVO observer. This observer was triggering before the view had a superview. Skipping updates that happen before the view has a superview avoid this issue. Thinking about that a little more and:
'UIView-Encapsulated-Layout-Top' V:[UIView:0x7fc461fc6620]-(0)-|
Makes me think the -(0)- is "oh, and the view is zero height, thanks for playing" because said view has no superview and auto layout just doesn't want to deal with that mess.
Hopefully I can get the hardware back in working order early October and find out what is what!
Maybe you have forgotten to set translatesAutoresizingMaskIntoConstraints = NO for some view that you added programmatically on which you are using constraints. That might explain the AutoresizingMask. Kindly check.
UPDATE:
Also, for this constraint:
<NSLayoutConstraint:0x7fc461fe9110 UICollectionView:0x7fc463090000.top == UIView:0x7fc461fc6620.topMargin + 302>
try changing UIView:0x7fc461fc6620.topMargin to UIView:0x7fc461fc6620.top
I am guessing you haven't accounted for the margin while calculating your constant "302"
I've disabled autolayout from xib. But I'm facing this issue. Even I'm not adding any subview programmatically, and I'm having 3 element in this view:
1. UIImageView 2. UIButton 3. UIButton.
I'm suffering for the last 3 days but I'm not able to find out the error. So please any one help me. Your help will be appreciated.
NSLog(#"Constratins %#",[self.view constraints]);
Constratins (
)
View hierarchy unprepared for constraint.
Constraint: <NSAutoresizingMaskLayoutConstraint:0x294d9de0 h=-&- v=-&- UIViewControllerWrapperView:0x2d91c410.midY == UINavigationTransitionView:0xdd2aa40.midY>
Container hierarchy:
<UINavigationTransitionView: 0xdd2aa40; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xdd2aca0>>
| <UIViewControllerWrapperView: 0x2a72b4d0; frame = (0 0; 1024 768); layer = <CALayer: 0x2a72ab40>>
| | <UIView: 0x2d869b30; frame = (0 0; 1024 768); gestureRecognizers = <NSArray: 0x2d8852e0>; layer = <CALayer: 0x2d86b510>>
| | | <MyImageView: 0x2d891040; baseClass = UIImageView; frame = (0 0; 1024 748); userInteractionEnabled = NO; layer = <CALayer: 0x2d8699f0>> - (null)
| | | <UIButton: 0x2d88c460; frame = (968 14; 40 40); hidden = YES; opaque = NO; layer = <CALayer: 0x2d88c550>>
| | | <UIButton: 0x2d88a220; frame = (963 9; 40 44); opaque = NO; layer = <CALayer: 0x2d88a310>>
View not found in container hierarchy: <UIViewControllerWrapperView: 0x2d91c410; frame = (0 0; 1024 768); autoresize = W+H; layer = <CALayer: 0x2d91c490>>
That view's superview: NO SUPERVIEW
Yes, I found the solution. The reason is : not setting the frame of UIViewControllerWrapperView
So i've do this
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.view.superview.frame = self.view.bounds;
}
I'm trying to show a simple settings screen in my app and I'm using Autolayout. Since my app supports landscape, and the settings controls don't quite fit vertically when the phone is landscape, I added a UIScrollview.
It seems that the combination of UIScrollview and Autolayout is a common question here and elsewhere. I've read a few articles on it, and from what it can tell, it seems that a good way to go for what I'm trying to do is to put my various controls within a view, like a "contentView" with constraints aligned in that view. Then have that contentView be the sole subview of the UIScrollView. I have the contentView with constraints tied to the edges of the UIScrollView.
UINavigationView -> UIScrollview -> contentView (UIView) -> Control Subviews
It works fine in portrait, even if I add content in my contentView that requires scrolling to see, but when I go to landscape, it doesn't let me scroll down far enough. It's like the content size gets reset to the frame of the visible area (or the frame of the navigation controller superview) when I rotate.
I'm wondering if I need to check for rotation and then set the content size again at that time? If so, is there a way to get that size dynamically from the view (contentView)?
Thanks for any help you can offer!
Jim
There are two components to having auto layout properly handle scroll views:
Constraints for scroll view's subviews: The contentSize of the scroll view will be dictated by the constraints of the scroll view's subviews. Thus, you need to have a bottom constraint for the last control in the scroll view (i.e. second switch) to its superview (i.e. the scroll view). It looks like you do have this. These constraints for subviews of the scroll view will automatically adjust the scroll view's contentSize as needed.
By the way, the constant for this second switch's bottom constraint will generally default to some largish value corresponding to how it was laid out in portrait. You may want to select and edit this bottom constraint for this last control and change it so that it's the "standard" value.
Constraints for the scroll view itself: You need to make sure you have the bottom constraint for the scroll view, itself, to its superview (and make sure you do not have a height constraint on the scroll view). This will adjust the frame of the scroll view upon screen rotation. I wonder if this might be missing in your project.
You can confirm this by running your app in the debugger, hitting "pause" button:
and then at the (lldb) prompt, type po [[UIWindow keyWindow] recursiveDescription], and you should see something like:
(lldb) po [[UIWindow keyWindow] recursiveDescription]
<UIWindow: 0x8b97ff0; frame = (0 0; 320 480); autoresize = W+H; gestureRecognizers = <NSArray: 0x8b98450>; layer = <UIWindowLayer: 0x8b97af0>>
| <UIView: 0x8b9a830; frame = (0 0; 320 480); transform = [0, -1, 1, 0, 0, 0]; autoresize = RM+BM; layer = <CALayer: 0x8b9a240>>
| | <UIScrollView: 0x8b9aa50; frame = (0 0; 480 320); clipsToBounds = YES; autoresize = RM+TM; gestureRecognizers = <NSArray: 0x8b9a6c0>; layer = <CALayer: 0x8b9a130>; contentOffset: {0, 0}>
| | | <UILabel: 0x8b9ade0; frame = (20 20; 63 21); text = 'Settings'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b9aec0>>
| | | <UILabel: 0x8b9d590; frame = (20 49; 51 21); text = 'View 1'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b9d6b0>>
| | | <UILabel: 0x8b9db70; frame = (408 49; 51 21); text = 'View 2'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b9dc10>>
| | | <UIView: 0x8b9de60; frame = (335 78; 124 53); autoresize = RM+BM; layer = <CALayer: 0x8b9dec0>>
| | | <UIView: 0x8b9e000; frame = (20 78; 284 53); autoresize = RM+BM; layer = <CALayer: 0x8b9e060>>
| | | <UILabel: 0x8b9e250; frame = (20 139; 59 21); text = 'Slider 1'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b9e2f0>>
| | | <UISlider: 0x8b9e460; frame = (18 238; 444 34); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x8b9e5c0>; value: 0.500000>
| | | | <UIView: 0x8ace410; frame = (2 16; 440 2); userInteractionEnabled = NO; layer = <CALayer: 0x8ace470>>
| | | | | <UIView: 0x8ace610; frame = (221 0; 219 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ace670>>
| | | | | | <UIView: 0x8ace6e0; frame = (-221 0; 440 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ace740>>
| | | | | | | <CAGradientLayer: 0x8ace7b0> (layer)
| | | | | <UIView: 0x8ace7e0; frame = (0 0; 221 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ace840>>
| | | | <UIImageView: 0x8ace9d0; frame = (207 1; 31 31); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8acea60>>
| | | | | <UIImageView: 0x8ace8b0; frame = (-13 -6.5; 57 43.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ace940>>
| | | <UISlider: 0x8b9e850; frame = (17 168; 444 34); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x8b9e930>; value: 0.500000>
| | | | <UIView: 0x8ba5430; frame = (2 16; 440 2); userInteractionEnabled = NO; layer = <CALayer: 0x8ba5490>>
| | | | | <UIView: 0x8acc190; frame = (221 0; 219 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8acae30>>
| | | | | | <UIView: 0x8acc3f0; frame = (-221 0; 440 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ac84d0>>
| | | | | | | <CAGradientLayer: 0x8accb90> (layer)
| | | | | <UIView: 0x8acdf50; frame = (0 0; 221 2); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8acdfb0>>
| | | | <UIImageView: 0x8ace070; frame = (207 1; 31 31); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ace100>>
| | | | | <UIImageView: 0x8acdfe0; frame = (-13 -6.5; 57 43.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8acdc80>>
| | | <UILabel: 0x8b9e9c0; frame = (20 209; 59 21); text = 'Slider 2'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b9ea60>>
| | | <UISwitch: 0x8b9ece0; frame = (411 279; 51 31); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x8b9edd0>>
| | | | <_UISwitchInternalViewNeueStyle1: 0x8b9f0c0; frame = (0 0; 51 31); gestureRecognizers = <NSArray: 0x8b723f0>; layer = <CALayer: 0x8b9f1c0>>
| | | | | <UIView: 0x8b9f750; frame = (35.5 0; 15.5 31); clipsToBounds = YES; layer = <CALayer: 0x8b9f7b0>>
| | | | | | <UIView: 0x8b9f3b0; frame = (-35.5 0; 51 31); layer = <CALayer: 0x8b9f410>>
| | | | | <UIView: 0x8b9f6c0; frame = (0 0; 35.5 31); clipsToBounds = YES; layer = <CALayer: 0x8b9f720>>
| | | | | | <UIView: 0x8b9f440; frame = (0 0; 51 31); layer = <CALayer: 0x8b9f4a0>>
| | | | | <UIView: 0x8ba11e0; frame = (0 0; 51 31); layer = <CALayer: 0x8ba1240>>
| | | | | | <UIImageView: 0x8ba0f10; frame = (39 16; 0 0); alpha = 0; userInteractionEnabled = NO; layer = <CALayer: 0x8ba10f0>>
| | | | | | <UIImageView: 0x8ba1120; frame = (12 16; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x8ba11b0>>
| | | | | <UIImageView: 0x8b9fab0; frame = (7 -6; 57 43.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8ba0a40>>
| | | <UISwitch: 0x8b974b0; frame = (411 318; 51 31); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x8b75570>>
| | | | <_UISwitchInternalViewNeueStyle1: 0x8b7d6a0; frame = (0 0; 51 31); gestureRecognizers = <NSArray: 0x8b845e0>; layer = <CALayer: 0x8b78750>>
| | | | | <UIView: 0x8b7df70; frame = (35.5 0; 15.5 31); clipsToBounds = YES; layer = <CALayer: 0x8b7be00>>
| | | | | | <UIView: 0x8b72410; frame = (-35.5 0; 51 31); layer = <CALayer: 0x8b7a660>>
| | | | | <UIView: 0x8b7ba80; frame = (0 0; 35.5 31); clipsToBounds = YES; layer = <CALayer: 0x8b7bd00>>
| | | | | | <UIView: 0x8b78dd0; frame = (0 0; 51 31); layer = <CALayer: 0x8b7ba20>>
| | | | | <UIView: 0x8b81580; frame = (0 0; 51 31); layer = <CALayer: 0x8b77ee0>>
| | | | | | <UIImageView: 0x8b97880; frame = (39 16; 0 0); alpha = 0; userInteractionEnabled = NO; layer = <CALayer: 0x8b7e1a0>>
| | | | | | <UIImageView: 0x8b77460; frame = (12 16; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x8b7e350>>
| | | | | <UIImageView: 0x8b80670; frame = (7 -6; 57 43.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8b80700>>
| | | <UILabel: 0x8b97cf0; frame = (335 284; 67 21); text = 'Switch 1'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b808b0>>
| | | <UILabel: 0x8b79d60; frame = (335 323; 67 21); text = 'Switch 2'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8b77b90>>
| | | <UIImageView: 0x8ac44f0; frame = (476 473; 3 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x8a89130>>
| | | <UIImageView: 0x8ac2be0; frame = (313 316; 7 3); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x8ac2c70>>
| | <_UILayoutGuide: 0x8b9cb20; frame = (0 0; 0 20); hidden = YES; layer = <CALayer: 0x8b9e5f0>>
| | <_UILayoutGuide: 0x8ac4440; frame = (0 320; 0 0); hidden = YES; layer = <CALayer: 0x8a90370>>
Check the frame of the UIScrollView (e.g. the above is for landscape on iPhone), and make sure it corresponds to the size of screen. If you haven't defined the constraints between the scroll view and its superview, this frame may be incorrect.
Maybe others will have a better solution for this, but the fastest without changing too much on your current build would be to do exactly what you said: check for rotation and then set the content size again.
It would be done like this in your Settings View Controller implementation file:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.scrollView.contentSize = self.contentView.bounds.size;
}
... assuming you have added in that same file outlets to your UIScrollView and your UIView named scrollView and contentView respectively.
My app uses a UINavigationController, but I do not show the toolbar because all of my navigation is controlled by in-game controls.
I do not have a Tab bar, because I'm not using a TabBarController.
My game app is Landscape only.
This is how I previously created and presented the UIActionSheet:
UIActionSheet *quitGameSheet = [[UIActionSheet alloc]
initWithTitle:#"Quit your game?"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Yes, quit game"
otherButtonTitles:nil];
[quitGameSheet showInView:self.view];
However, the UIActionSheet is mostly off screen and I get this error:
Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].
However, I do not have a toolbar and I do not have a tabbar.
I've tried several other Stack Overflow answers, none of which work for me:
Issue with UIActionSheet
I tried presenting it from self.navigationController.view, from self.parentViewController.view, from a CGRect that I created which was at the bottom of the view, from self.view.bounds because I was desperate.. none of it works for me.
It works in iOS 6, but does not work in iOS 7. Here are a couple of screenshots of it working on iOS 6 and failing on iOS 7.
Any help?
UPDATE 1 ---
Here is a view hierarchy as requested:
<UIView: 0xc480380; frame = (0 0; 568 320); autoresize = RM+BM; layer = <CALayer: 0xc4803e0>>
| <UIImageView: 0xc480410; frame = (0 0; 568 320); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xc4804a0>>
| <UIButton: 0xc47b370; frame = (203 107; 159 37); opaque = NO; autoresize = LM+RM+BM; layer = <CALayer: 0xc47a730>>
| | <UIImageView: 0xc475150; frame = (0 0; 159 37); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc4751e0>>
| <UIButton: 0xc478a00; frame = (203 152; 159 37); opaque = NO; autoresize = LM+RM+BM; layer = <CALayer: 0xc477dd0>>
| | <UIImageView: 0xc475030; frame = (0 0; 159 37); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc4750c0>>
| <UISwitch: 0xc47dcc0; frame = (313 65; 51 31); opaque = NO; autoresize = LM+RM+BM; layer = <CALayer: 0xc47d180>>
| | <_UISwitchInternalViewNeueStyle1: 0xc47e040; frame = (0 0; 51 31); gestureRecognizers = <NSArray: 0xc47ffa0>; layer = <CALayer: 0xc47e140>>
| | | <UIView: 0xc47e4e0; frame = (35.5 0; 15.5 31); clipsToBounds = YES; layer = <CALayer: 0xc47e540>>
| | | | <UIView: 0xc47e330; frame = (-35.5 0; 51 31); layer = <CALayer: 0xc47e390>>
| | | <UIView: 0xc47e450; frame = (0 0; 35.5 31); clipsToBounds = YES; layer = <CALayer: 0xc47e4b0>>
| | | | <UIView: 0xc47e3c0; frame = (0 0; 51 31); layer = <CALayer: 0xc47e420>>
| | | <UIView: 0xc47f750; frame = (0 0; 51 31); layer = <CALayer: 0xc47f7b0>>
| | | | <UIImageView: 0xc47f480; frame = (39 16; 0 0); alpha = 0; userInteractionEnabled = NO; layer = <CALayer: 0xc47f660>>
| | | | <UIImageView: 0xc47f690; frame = (12 16; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0xc47f720>>
| | | <UIImageView: 0xc47e680; frame = (7 -6; 57 43.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc47f2f0>>
| <UILabel: 0xc480610; frame = (173 63; 96 29); text = 'Sounds:'; clipsToBounds = YES; opaque = NO; autoresize = LM+RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xc480540>>
| <UIButton: 0xc473a20; frame = (203 197; 159 37); opaque = NO; autoresize = LM+RM+BM; layer = <CALayer: 0xc473590>>
| | <UIImageView: 0xc474f30; frame = (0 0; 159 37); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xc474fc0>>
I had what appeared to be a completely unrelated problem in the same app, wherein some of the buttons on the left side of the screen weren't tappable.
Can't tap buttons on the left side of 4" iPhone
While investigating that I discovered that my UIWindow was 320x480. The problem was in my MainWindow.xib. Xcode created this xib for me, but it was probably Xcode 3 and it was several years ago. I decided to review the settings and I noticed the option for "Full Screen at Launch." I looked up that option in the docs and there was a note stating that this should always be on so that the Window is properly resized to match the device size. This was never an issue when there was only one size iPhone, but it became a problem with the introduction of the 4" iPhone.
So, I checked that box, and relaunched and viola, both this and the other problem were solved because the enclosing UIWindow was correctly sized.
I have recently solved a similar issue happening on iOS 7 (although it did not involve an action sheet) by presenting in the main window; in your case it would be something like:
[quitGameSheet showInView:[UIApplication sharedApplication].keyWindow];
hope it will work in your case as well.
[sheet showInView:[UIApplication sharedApplication].keyWindow];
sheet.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-
sheet.frame.size.height, [UIScreen mainScreen].bounds.size.width,
sheet.frame.size.height);
Link: Issue with UIActionSheet
Form: user352537