Why is my UIWebView displaying nothing after I pull it onscreen? - ios

I have a series of three UIWebViews, arranged side-by-side, each one sized to be full screen.
One of them is 'current', one is 'next', and the last is 'previous'. I have each one populated with test data currently (aptly named 'test one' 'test two' 'test three'). Long term I'll have more than three items to deal with.
Swipes cause the entire shebang to 'rotate' left or right, displaying the next / previous item in the cycle. The code for the rotation works, as far as I can tell, correctly. Current takes on the frame of previous, previous takes on next's frame, and next takes on the frame of current. I then adjust the pointers so that current is pointed to next (which is now placed as current) and so on. Sounds more complicated than it really is:
//code to animate this process properly ommited
previous.hidden=1
CGrect tempFrame=current.frame;
current.frame=previous.frame;
previous.frame=next.frame;
next.frame=tempFrame;
previous.hidden=0
//Adjust the actual pointers so they accurately describe their current positions
UIWebView *temp=current;
current=previous;
previous=next;
next=current;
My only issue is that the web views if you go 2 or more in a given direct slide in 'blank'. E. G. swipe right and you go from test 1 to test 2. Swipe right again, and you get a blank screen. THe frames are all correct, the webview is placed correctly, but it's contents are blank.
Confusing thing is, if you swipe once in the opposite direction, and then back, it displays properly. (E. g. swipe three right, you have a blank; swipe left then back right, and it displays the 'correct' screen.)
Does anyone have any ideas what could possibly be causing this? I suspect that once I go to my next step ('real data' where next / previous is loaded with the appropriate item when it's slid in) it'll cause the current issue to vanish, but I want to understand THIS issue.
Edit:
I've managed to trace the issue, partially, to my 'hiding' the panel that should NOT be visible. Past that, I'm still not sure what is going on.

Turns out that it's related to hiding the 'unused' view in the shuffle. Why it works when I move backwards to it I don't know. By moving the 'unused' view to the very back of the order, everything works right.

Related

How can I stop objects from disappearing?

I'm developing a game with Buildbox and I'm facing a problem that I have no idea how to solve.
In practice I am making a vertical scrolling game where you can only go up. An endless climb in which to avoid obstacles, traps and so on.
To move the gameplay a little, I decided to insert a pinball section in which to hit objects with a ball to break free and continue the climb. The problem I have concerns the levers to hit the ball.
If I try the stage individually there are no problems, but if I pass the stage to come back again and continue the game normally, the sticks tend to disappear after a couple of interactions with them.
The yellow points are the levers, the blue points are the triggers that bring the levers back to the starting position if they should go out of place
I have already tried the following solutions:
Add a spawner command, but the result is a constant spawn of the stick in the starting position compared to what I need. Even if the lever receives interaction or command to move.
Tie the lever to other fixed elements of the scenario, but the result is that the lever does not move, rightly.
Tie the lever to other movable elements of the scenario.
Increase the back and side deletion threshold.
Cancel and redo the levers.
I noticed that the levers disappeared because I moved them while passing from one stage to another. They disappeared because the button to make the character jump is superimposed on the one to move the levers. I made sure that the buttons did not interpenetrate, but nothing changed, the only thing I got is that the levers are not already gone when I return to the stage, but that they disappear as soon as I move them again.
I also tried to remove the triggers, but the levers do a thousand turns on themselves and then disappear anyway.

UIPageControl select dot and go to that page

I have aUIViewController, which has inside a UIView in which I add a UIPageViewController with the UIViewController as the delegate. The thing is that the UIPageControl of the UIPageViewController is not working as I had expected regarding the dots selection.
I was expecting that if I selected the dot 4, it would take me to the dot 4, yet, It doesn't work like that. It always goes to the following page if I select the right half of the UIPageControl (inside the blue square of the image), and goes to the previous page if I select the left half of the UIPageControl (inside the red square of the image). So, If im in page 2 and select around the second dot, it goes to page 1 (instead of staying on page 2)
Moreover, If I click exactly inside one of the dots (any of the dots), the click is ignored, although im not sure how this works on device (since in the device is more difficult to click exactly inside one dot).
My questions:
1 - Is ignoring exactly inside the dots behavior normal (by exactly inside the dots, I mean not around them)?
2 - Is two halves selection of the UIPageController to move between pages behavior normal?
3 - How can I make it so that if I press the dot X, it takes me to page X (instead of the current two halves behavior)?
Note: I prefer swift
1 - Is ignoring exactly inside the dots behavior normal (by exactly inside the dots, I mean not around them)?
I've never encountered this. I would say its not normal. Something may be overriding it.
2 - Is two halves selection of the UIPageController to move between pages behavior normal?
Yes this is the default behavior for UIPageController.
3 - How can I make it so that if I press the dot X, it takes me to page X (instead of the current two halves behavior)?
I would recommend not doing this. The reason that it isn't this way by default is the touch space is too small (when using a finger not a mouse). So it makes sense to only go forward and back. You'd have to create a custom UIControl to be able to do this if you really need to for some reason.
I would suggest you to use external library for that, as this problem was more or less solved. It is quite complicated to do by subclassing native page control but you can probably find implementation somewhere.
This library does exactly what you want (jump to page) :
https://github.com/Spaceman-Labs/SMPageControl
In the documentation, look for section "Direct Page Selection"
Hope it helps!
Edit: Few more libraries to look into:
https://github.com/TanguyAladenise/TAPageControl
https://github.com/nicklockwood/FXPageControl (very extensive, probably too much)

iOS View Controller is only accepting touches in a certain portion of the window

I have a relatively simple dialog/popup style UIViewController that isn't behaving correctly. I have many others just like it (though each with a unique button layout) that work just fine. For some reason that I cannot figure out, this controller is only accepting touches within (approximately) the green shaded area.
Note that none of these colors are the actual colors, just placeholders. Same goes for the text.
Tapping in the "Search..." text field does nothing. Tapping on the "Cancel" button does nothing. No UI reaction whatsoever.
The tableview will scroll just fine (there are over 100 rows) if it's touched inside (approximately) the green region. Touching the tableview below the green results in no response. Same thing for the "Cats" button. It reacts when touched in approximately the top half, but nothing in the bottom half.
I've banged my head against the wall for the requisite "several hours" and am getting nowhere.
It seems that part of your view controller's view is overlapped with some "harmful" view/views. Maybe this view is created programmatically and is not visible in IB. You should start with checking your views hierarchy. Put breakpoint in your view controller's code. Somewhere, where you are sure all views (normal and harmful) are already created and type in debug area
po [self.view recursiveDescription]
you should receive something like
Now try to find harmful views. Temporarily delete some "normal" views could be a good idea.
I found my solution. I have a method that launches a dialog controller given the dialog to launch and the parent (up until this point, always a full-screen view controller). The parent gets darkened and the dialog gets launched on the center of the screen.
This one wasn't working because I was launching it from an existing dialog; I was telling the dialog launcher that the new dialog's parent was the current dialog, not the whole screen. This means that the new dialog (which is bigger than the first one) launches at the correct size, but only accepts input inside the area of the "parent" dialog, which is the smaller one underneath it.
Fix: Launch the new dialog using the current dialog's parent (which is full screen) and it works fine. The green zone on my image is the approximate size of the dialog that was being used as the parent, which is why input was only being accepted in that area.

Dragging an uiview like facebooks menu slide

I know this has been probably asked before but I've seen many approaches and i don't know which is best for me, so plz don't send me a link to another post unless it addresses my problem directly.
I have a controller which has a uiview on the top (like a header) (this header is bigger than it seems because is partially hidden on top). on that view i have a uibutton which now with a touch up inside shows the entire header view and taping again returns it to its starting position (changing frame with animation). I want to also be able to drag the view but only changing position on the y axis(dragging up and down)... i was thinking of adding the dragInside/Outside event to the button but this doesn't give me the position of the finger... and also want to know when the user releases the drag so the view ends animation to any of its two possible states (showing or partially hidden). Is this a "touches began" , "touches moved" , "touches ended" thing? if it is please provide a code example. I also want to do this with another view but this is on the left side... same thing but this one moves on the X axis... any help is appreciated. or maybe it can be made with drag event if i only can save a CGpoint of last touch, maybe that's better, any other suggestions
Look at using a UIPanGestureRecognizer to detect the touch movements. Use the translationInView: of the gesture to set the view y position. The translation is the total movement since the start of the gesture so you don't need to remember and accumulate the offset position yourself.
The main thing to worry about while implementing this is bounding the y position of the view so that no matter how far the user drags the view won't go too high or low on the screen.
Use a UIPanGestureRecognizer, that's a class dedicated to handling such drag/pan gestures.
Everything is described here in Apple's documentation, including examples, so you should find your answer here.
There is also some sample code in Apple Developer Library that shows you how to use Gesture Recognizers if needed.

Suppess UIView re-layout when child view changes

See UPDATE below:
I am confused about UIView layout as subviews are moving. I have a "Surface" UIView with several "Item" subviews on it. The user is allowed to click on the items and drag them around the surface.
What I have noticed though is that whenever a Surface's Item subview moves (is dragged by the user), the Surface is marked as needing to be relayed out.
I do not want the Surface to layout the Items after the user moved them. That is pretty much the whole point, I am allowing the user to position them as they see fit. However, there are times, initial creation is a prime example, where I do need the Surface to place the items.
So I would like one of two things:
A) Suppress SetNeedsLayout() calls on the surface when one of its Item subviews changes (moves).
--OR --
B) Know why I was asked to relayout, and if it was caused by Item motion then do nothing.
I cannot imagine I am the first to have this question.... :)
###### UPDATE:
After more investigation, I discovered more about what is going on. It is not that moving the Surface's items causes a Surface relayout, as I originally thought. It was only the initiation of a drag which caused the relayout. In digging further I discovered that it wasn't even the drag that was the cause, but a call to the Surface's bringSubviewToFront.
I need to bring the Item to the front, so that when it is dragged it appears on top of the others.
I can understand why bringing a subview might trigger a relayout, but again it is not what I want to happen.
May be you should override layoutSubviews in your Surface UIView.

Resources