Moving a UIView containing UIButtons makes those buttons stop respond to taps - iphone

I have a UIView in a UIScrollView in a UIView in a .xib that contains several buttons. If I move that UIView down by several pixels from within viewWillAppear, the buttons all stop responding to taps.
Here's the code I'm using to resize the UIScrollView and shift the buttons down:
// adjust the view height to accomodate the resized label
scrollView.contentSize = CGSizeMake( 320, 367 + expectedLabelSize.height - originalLabelSize.height );
// Adjust the location of buttons
CGRect buttonsBounds = buttons.bounds;
buttonsBounds.origin.y -= expectedLabelSize.height - originalLabelSize.height; //XX
buttons.bounds = buttonsBounds;
If I comment out the line marked XX, the buttons work just fine, but are in the wrong place of course.
If I try various numbers of pixels (replacing expectedLabelSize.height - originalLabelSize.height with a hardcoded value), I get interesting results. 10 pixels works fine. 50 pixels causes my top button to work fine but my bottom one to fail. 100 pixels and both buttons fail. (-50) pixels causes the bottom button to work fine but the top to fail.
Any idea what might be causing the problem? Do I somehow need to inform the buttons that their parent view has moved?

The problem was that I should have been using buttons.frame instead of buttons.bounds. Using the frame instead fixed the problem.

I suggest giving the parent UIView a background color and setting the button style to Rounded. That way you can actually see what is happening on the screen. (Assuming you are using transparent buttons on top of some image or so)

Related

Resizing a UIView containing UIButtons makes those buttons lose perspective position

I got a UIView that contains an UIIMageView and several buttons that are allocated on certain position related to the image of the UIIMageView.
The frame of the UIView is (0,0,250,250)
the UIIMageView that is within the UIView is set to autorisizing (all) in IB.
All buttons are set to autoresize (none) and origin middle.
When i change the frame of the UIView i.e (0,0,500,500) the UIIMageView (and image) resize OK but the buttons lose their perspective position by a few pixels (about 2 to 3 in the vertical and horizontal axis).
Is this normal? can someone advise?
Try putting the buttons inside another UIView and then setting the autoresizing options on this new view. You should leave the buttons without autoresizing inside the new view.
there is no answer after all.
I must accept the fact that the resized view and the buttons within it will lose perspective position by 2/ 3 pixels off the x/y axis...
strange....

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

Nested uiScrollViews with Cross-Directional Scrolling

I would like to nest two uiScrollViews, I want to put a uiImageView into one and have it scroll horizontally (Scroller A). This is paged and contains images – I have this working OK already. I need to have another uiScrollView (Scroller B) that contains the above scroller A and also other content, like logo, text and buttons. I would like scroller B to be able to scroll vertically (scrolls all content including scroller A ).
Please see image for clarification, red arrows show scroller A, blue is scroller B
Image showing more details
I’m not sure how to add these and what order the scrollers need to be added, I have attempted this a couple of times with strange results, I'm hoping someone can point me in the right direction please.
A similar app would be the apple app store app.
Keep a vertical scroll view add a fixed size view (which contains your horizontal scrollview) on it and increase its content size accordingly.each view will have Preloaded horizontal scroll view.
for(int i=0;i<10;i++)
{
y=i*110;
secondScroll=[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, 320, 100)];
[secondScroll setContentSize:CGSizeMake(600, 45)];//to enable scrolling content size is kept more the 320
secondScroll.backgroundColor=[UIColor greenColor];
[self.firstScroll addSubview:secondScroll];
[secondScroll release];
[self.firstScroll setContentSize:CGSizeMake(320, self.firstScroll.contentSize.height+110)];
}
first scroll is added on xib second scroll is created by code

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.

Hiding elements outside of bounds on iPhone

I'm trying to get a UIView to expand (with animation), sort of like an accordion menu. I can get the animation working fine however the issue is the subviews of the UIView are expanding past the bounds of the UIView.
For example, the view has an UILabel in the top-right corner with a height of 16. Assume the UIView height is 0 at the beginning of the animation. One would expect that the content of the view be hidden and gradually reveal as the UIView grows. Once the height has reached 8, for example, half the label should be visible. However that isn't the case - rather, the label is visible the whole time, regardless if it's height extends outside of that of it's parent view.
Any ideas how to resolve this?
Okay, I had to set the clipsToBounds property to true. I spent some time googling before making the question but didn't have much luck until I saw it in the Related section of my question.