开发者

UIButton stops responding after going into landscape mode - iPhone

I've been trying different things the last few days and I've run out of ideas so I'm looking for help. The situation is that I'm displaying my in-app purchasing store view after the user clicks a button. Button pressed, view is displayed. The store shows fine. Inside this view, I have a few labels with descriptions of the product, and then below them I have the price and a Buy button which triggers the in-app purchase. Problem is when I rotate the phone to landscape, that Buy button no longer responds, weird. Works fine in portrait.

The behavior in landscape when the I touch the button is nothing. It doesn't appear to press down and be selected or anything, just not responding to my touches. But then when I rotate back to portrait or even upside down portrait, it works fine.

Here is the rough structure of my view in IB, all the rotating and layout is setup in IB. I set the autoresizing in IB so that everything looks ok in landscape and the Buy button expands horizontally a little bit. The only layout manipulation I do in my code is after loading, I set the content size of the scroll view.

File Owner with view set to the scrollView      
/ scrollView  
----/ view  
--------/ label  
--------/ label  
--------/ label  
--------/ label  
--------/ label  
--------/ label  
--------/ la开发者_如何学Pythonbel  
--------/ label  
--------/ uibutton (Buy)  

After orientation changes I printed out the userInteractionEnabled property of the scrollView and the button, and they were both TRUE at all orientations.

Ideas? Or maybe some other way of displaying a buy button that won't be nonfunctional? I've already begun a branch that plays with a toolbar and placing the buy button there, but I can't seem to get the bar to stay in place while scrolling.


It sounds like you got around your issue, but just in case others come looking, I ran into a similar issue and found a solution.

I was programmatically adding the scrollview. I would then call setContentSize to make sure the scrollview was as tall as the view I wanted to show. The view I was showing was setup with both UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleHeight.

When I rotated to Landscape mode while testing, it looked like my subview was all there but I couldn't click on anything when I scrolled down. I think the issue was that since my subview was setup to have a flexible height, it was being shrunk vertically when the scrollview shrunk. Perhaps I was still seeing it as expected because I wasn't clipping or something?

Either way, once I only had my subview have a flexible width, everything works again. You should be able to turn off flexible height programmatically or in interface builder (the arrow in the box pointing up and down).


Since I couldn't get that UIButton to work correctly, I ended up just scrapping the button and creating a new parent view containing everything I currently have and then adding a toolbar below it and placing a button on there. This problem really didn't seem like it warranted this much of my time which is why I just went a different way.

File Owner with view set to the parent view  
/ view
----/ scrollView  
--------/ view  
------------/ label  
------------/ label  
------------/ label  
------------/ label  
------------/ label  
------------/ label  
------------/ label  
------------/ label  
----/ toolBar  
--------/ barbutton (Buy)  


Mmmm, maybe the button is within a UIView that not rotates as device do, then you view your button as always but out of the view container that propagates the touches.

You can check, in IB, the anchor of the view within its containers or do coding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜