iPhone UIScrollview: Button does not respond when located below 480 pixels on Scroll View's child UIView - iphone

I have built a view for an iPhone app in Interface Builder. It is a UIScrollview with a UIView and a UIButton on the UIView. The only code I have is setting the scroll view's contentSize to 320x550 in the viewDidLoad method of the xib's File Owner class. When the button is within the normal view area (320x480) the button responds as normal, but if is placed outside of those boundaries in Interface Builder the button will not respond when I scroll to it and click the button.
What am I missing? I figure it might be something I need to set on the UIView. But I am not sure what that is.

Your UIButton won't response even it's visible because it's not in the boundary of parent view. You can see object outside the boundary of its parent view because it's a default behavior of UIView to draw all subview (clipsToBounds = NO)
To see the truth, try this code.
UIView *yourUIView = ...
yourUIView.clipsToBounds = YES;
yourUIView.backgroundColor = [UIColor cyanColor];
You will no longer see your UIButton.
To fix this, enlarge your UIView.

I had the same problem as the person who posted the question. Thanks to the first answer, I had a hint as to what to do. I increased the height of the view by adjusting the frame. This, apparently must be done in code. Once this was done, however, the toolbar at the bottom was no longer visible. So before I adjust the height of the view, I grab the position of the tool bar. Then after adjusting the height of the view, I reset the position of the tool bar. Now all is good.

Related

iOS Swift : Keep UILabel constantly centered in UIView that changes height

I have a UILabel centered within a UIView that expands/contracts depending on the device screen size. I've applied constraints so that the UILabel remains centered no matter the UIView size, which works fine.
Now I'm finding myself resizing the UIView manually like so (where mainView is the View Controller):
self.myView.frame = CGRectMake(0,0,self.mainView.frame.width, self.mainView.frame.height)
So this stretches the UIView to fill the whole screen/View Controller (it's also animated). I assumed the UILabel would continue to centre itself automatically, but it seems to pin itself as though it were constrained to the top of the UIView, leaving a lot of empty myView space below it.
How can I tell the UILabel to remain in the centre of the height-changing UIView that it's in?
We need to see your constraints to help, but:
You need to use centering constraints.
Set the bounds, not the frame of myView.
You might need to call setNeedsLayout on the view of the ViewController you are in
Also, set the background color of the UILabel -- it could be centered, but the text is not centered inside of it. For that, set the alignment properties.

IOS UIScrollView: Cannot scroll until the end of the content

I am trying to generate a scroll controller in a window with the UIScrollView class, which will contain numerous UIButtons, placed vertically. I set the size of the scroll view equal to the current view controller's root view, so that the scroll view covers the entire visible window. Then I generate the UIButtons I am going to add to the scroll view: I add each UIButton just in the below of the previous UIButton and I add the height of the current UIButton to a variable called "totalContentHeight". Finally, I set the height of the contentSize of the scroll view to this value, in the following line of code:
self.scrollViewForNewsButtons.contentSize = CGSizeMake(self.view.frame.size.width, totalContentHeight);
totalContentHeight is equal to numOfButtons*eachButtonsHeight after I add all the buttons to the scroll view.
The problem is, in the simulator, when I run the app and scroll until the end of the last button and release the mouse, the last two buttons bounces back such that they lie outside of the visible window. It is somewhat hard to express with mere words, so here are the images:
1)This is what I get when I scrolled until the end of the content and held the content at the last possible position it could be pushed:
2)This is what I get after I released the mouse and the scroll view bounced back to its final position:
As you can see, the last two buttons are drawn outside of the visible area. It is like the scroll view's area covers the whole window plus the button area of the IPhone. I could not find a reasonable explanation for this. Am I setting the area size wrong or am I missing something else?
just set content size with calculation with your total button and its height...For Ex..
float yheight = totalButton * yourButtonHeight;
[yourScrollView setContentSize:CGSizeMake(320, yheight + 44)];
try this code...
And if you set the scrollview frame size the same as
self.view.bounds

xCode 4.2 iOS5 interfaceBuilder cannot tap on a button that is laid out in the IB

I've ran into a weird issue lately:
I have a 320 x640 UIView within a UIScrollView. I've manually positioned buttons throughout the view and assigned actions to them. One of the buttons has a center at [x,y]: [287,440]. The button is 60x60.
I can tap all other buttons and controls located as low as Y = 353.
I see that the button is located on the same level as all of my other buttons, within the same view as them.
What could be causing my button to be completely untappable? I have another controller, which is also "tall", and there buttons located "off screen" are tappable. [If I move the button up to the level of other buttons, it works as expected.]
Here's the scroll view code:
self.scrollView.contentSize=CGSizeMake(320, 640);
Something is covering it. Try looping over all subviews and printing origin.y relative to scrollview origin.y, and then height plus relative position. Do this in viewWillAppear. Be aware that autoresizing behavior can kick in right after viewDidLoad and fool you. That is what happened to me earlier. There will be an overlap somewhere.
Can post code example later from home if this doesn't get you through it.

Problem with UIScrollView inside another UIView

I have this UIScrollView inside another UIView, not occuping the entire area (all this is initialized via nib file). I added some content to the scroll view, but whenever I scroll it, the UIScrollView content area moves outside the ScrollView frame, over the UIView area not designated for displaying it.
Shouldn't it remain inside its frame even when I scroll it?
It may be that the clipsToBounds property of your UIScrollView is set to NO. Check the setting in IB, or you can set it in code like so:
scrollView.clipsToBounds = YES;
Failing that, double check that your UIScrollView has exactly the bounds you think it does. Is there any autoresizing flag stuff going on that might be changing the scroll view's bounds?
try to set the clipsToBounds to YES, it may be that:
yourViewController.clipsToBounds = YES;
if not... fbreto is right, post your code...
Make sure you have setContentSize. And also set the frame size of the uiviews inside the uiscrollview correctly when you add them.
Here is a sample code of it http://developer.apple.com/library/ios/#samplecode/Scrolling/Introduction/Intro.html

iPhone UIButton Parent Frame Changing Touch Up Inside Event Issue

I have a UIButton within a UIView. The button is docked on the bottom of the view using the Autoresizing Masks. The button is working fine when the view initially loads and the IBAction is being called successfully.
Now when I resize the height of the parent view the button stays docked at the bottom of the view, however now only half of the button responds to the touch events. If I resize the parent view height a bit larger then the button completely doesn't respond anymore.
Any ideas why this would be occurring?
It sounds as if you've got another view, most likely a transparent one, that is resizing improperly and covering up part of the button.
It seems that I was moving the main view as the inner view height was changing. I guess if the UIButton is outside the bounds of the self.view then touches are not received.