Is there a way to make the WKWebview a firstResponder? - wkwebview

The Main idea is to reload the WKWebView if there is no touches or presses detected (i.e When webView remains inactive for some timeinterval ) . I tried the way to implement
touchesBegan(_:with:) and
touchesEnded(_:with:)
I have overwritten those functions . But these functions are not called when a touch is detected . This function is called when an TextField is present and touches inside the textfields are detected . But why it is not working in WebView .
I found that to make the touchesBegan and touchesEnded functions work , I need to make the object an first responder .
I used
print(myWebView.canBecomeFirstResponder) // Return True
myWebView.becomeFirstResponder()
print(myWebView.isFirstResponder) // Return false
I dont know how to make webview an firstResponder and also is there any other ways to detect presses/ Touches while in WKWebView . Can Anyone help me? And Thank you In Advance

Related

Identify Reference to Destroy & Re-Initialize Swiper in Elementor

Elementor Pro (the WordPress page builder) integrates beautifully with Swiper, tying their GUI to the JS parameters and database content.
However, for my project, I need to make some changes to the Swiper "CoverFlow" skin Init parameters (show more slides, change the 3D effect facing direction...).
My hope is to to use the Destroy method of the Swiper API which looks like:
mySwiper.destroy(deleteInstance, cleanStyles);
Then I can initialize the Swiper again, with my own custom parameters. The challenge is that the way Elementor calls Swiper in frontend.js is a complex anonymous function that doesn't really allow me to know what "mySwiper" would be... On line 567:
this.swipers.main = new Swiper(this.elements.$mainSwiper, this.getSwiperOptions());
I would be so grateful if someone could please help me understand what "this.swipers.main" would translate to after Init so that I can destroy the swiper and initialize it again with my own parameters.
Obviously I cannot edit frontend.js itself as it is a plugin file that needs to be updated.
Extra points for whomever teaches me how to fish and what the methodology is to solve these types of puzzles for other similar situations.
You can give an ID to the Elementor widget ex: slider1 and then with JS you can use:
var sliderInstance = document.querySelector('#slider1 .swiper-container').swiper;
After this you can call sliderInstance.destroy() wherever you want.
And if you want to initialize it again you can call:
var sliderInstance = new Swiper('#slider1 .swiper-container', {
//options
});

Xcode 9 UITextView links no longer clickable

Prior to Xcode 9 and iOS 11 I had a UITextView within a UITableViewCell that contained multiple links. Each link worked as expected, however since upgrading to iOS 11 and Xcode 9, the links no longer work.
The UITextView doesn't appear to recognise any touch interaction with func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool never firing.
Has anyone else found this same problem after upgrading?
Turns out there wasn't a problem after all. Changes in the way UITextView responds to touches in iOS11 means that clicking links requires more of a press rather than just a tap which previously worked in iOS10. I think this may be something to do with the fact that in iOS11 you can now press links and drag them which also displays details of URL. So a firmer press is needed for the UITextView to register the link being tapped.
Specifically in iOS 11.0 and 11.1 (not later in 11.2+, not earlier in 10.x), textView(_:shouldInteractWith:in:interaction) from UITextViewDelegate is called from an interaction with a UILongPressGestureRecognizer instead of a UITapGestureRecognizer.
For those two iOS versions, user needs a small delay long press instead of a tap for a native interaction with UITextView links.
If the callback doesn't get called at all for those two iOS versions, even on a long press, you've likely been messing with gesture recognizers by subclassing your UITextView and overriding gestureRecognizerShouldBegin(_) to return false when it shouldn't.
Here is an example of quick partial workaround for gestureRecognizerShouldBegin(_) that will disable loupe/magnifier long press (if that's the desired intent of the override), but still allow long press on links:
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UIPanGestureRecognizer {
// required for compatibility with isScrollEnabled
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let tapGestureRecognizer = gestureRecognizer as? UITapGestureRecognizer,
tapGestureRecognizer.numberOfTapsRequired == 1 {
// allowing taps for links
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let longPressGestureRecognizer = gestureRecognizer as? UILongPressGestureRecognizer,
// allowing small delay long press for links (required for iOS 11.0-11.1)
// average comparison value is used to distinguish between:
// 0.12 (smallDelayRecognizer)
// 0.5 (textSelectionForce and textLoupe)
longPressGestureRecognizer.minimumPressDuration < 0.325 {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
gestureRecognizer.isEnabled = false
return false
}
An alternative is to fully disallow both UILongPressGestureRecognizer and UITapGestureRecognizer except for a self-made UITapGestureRecognizer that you would have build yourself to interact with links.

How to get text on unity 2D to display

I can't display text and I get a NullReferenceException when the method is executed. On top of that the code doesn't stop running as it should.
// Use this for initialization
void Start()
{
// Default position not valid? Then it's game over
if (!isValidGridPos())
{
Text text;
text = GetComponent<Text>();
text.text = "Game Over";
Destroy(gameObject);
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
The code comes from this tutorial. I just wanted to add it a restart and a Game Over message.
EDIT: Trying to display text with text = GetComponent() is not working. What's another way to display text on unity that actually works? I tried GUIText too but I can't make it visible on display.
I have looked at the tutorial and they have the following code:
if (!isValidGridPos()) {
Debug.Log("GAME OVER");
Destroy(gameObject);
}
This works because it prints to the debug log console. You obviously want to capture that and print it on the screen. This requires a canvas and a text component being added to the gameobject the script is on. Declaring a text variable here won't add one to the game object, it has to be done in the unity inspector.
The following code:
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
Shouldn't be here, as this object will already be destroyed this code will be rendered useless unless you are holding the key down in the same frame that the object is created. It should instead be on in another script on a gameobject that won't be destroyed and it will await an r key to reload the level.
If text = GetComponent<Text>(); isn't working it could be because your Text component is not on the same gameobject that your script is attached to.
In the Unity Editor, check that the text component and your script are on the same gameobject
Did you inspect editor view while running?
Don't use destroy in Strar().
You can set delay like so Destroy(gameobject, 5.0f) and use it in some other callback function (ex. Action).
Now you just destroying whole gameobject all its scripts and components(including Text) right after it initialized. If it is in scene from beginning, then it destroyed as soon as you press Play.
Start() runs just once so what does isValidGridPos() doing?

Cocos2d-x - How can I add a sprite in the GameScene which is called from another class?

I have a GameScene class which is similar to HelloWorldScene in the project template. How can I add a sprite and display in the scene of the GameScene with addChild method which is in the another class?
Example, I have 2 class: GameScene and Board is a normal class. In init method of GameScene I call board->initBoard() with board is a object of Board class. How I add addChild(sprite) in initBoard() ?
I tried with some ways but it still is not sucessfull. I'm using Cocos2d-x v3.0rc1.
First of all, this is a bad design! Why is a child class adding stuff to its parent while being initialized itself?
But if it is such a requirement, then I would do something like,
the bad way
(In GameScene)
Board* board = new Board();
this->addChild(board);
board->initBoard();
meanwhile in boardclass,
void Board::initBoard(){
.
.
.
getParent()->addChild(sprite);
}
Even though I don't like it, it will work.
Yet another way would be,
the OK way...
Board::initBoardWithParent(GameScene* scene){
.
.
.
scene->addChild(sprite);
}
in GameScene...
Board* board = new Board();
board->initBoardWithParent(this);
In this case(for some people), errors start popping up... so make sure ur scene is declared with a preprocessor...otherwise it will make ur compiler scream as it would get crazy compiling GameScene since it is using Board which itself is using GameScene...
#ifndef __GAME_SCENE_H__
#define __GAME_SCENE_H__
...
...
class GameScene : ....
#endif // __GAME_SCENE_H__
The decent way...
Yet anotherway would be that you override the ADDCHILD Method of ur Board class...
And as you do that, make sure you pass an extra parameter indicating that this is a special ADDCHILD, and once u get there... using either of the 2 methods mentioned earlier to add the sprite to the GameScene object.
Hope this helps!

iOS 4.2 Block Animation --> Why do I get these warnings: -[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring

I've got some code that wobbles UIViews, much like when you edit your iOS home screens.
I have the 2 following methods to achieve this wobble effect:
- (void)wobble {
int amountInRadians = (self.tag % 2) == 0 ? 2.0 : -2.0;
containerView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-amountInRadians));
[UIView animateWithDuration:0.10
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse)
animations:^ {
containerView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(amountInRadians));
}
completion:NULL
];
}
- (void)stopWobble {
[UIView animateWithDuration:0.01
delay:0.0
options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear)
animations:^ {
containerView.transform = CGAffineTransformIdentity;
}
completion:NULL
];
}
When I stop the wobble, I get the warning (many times over):
-[UIApplication beginIgnoringInteractionEvents] overflow. Ignoring.
then (many times over, matching number of begin ones):
-[UIApplication endIgnoringInteractionEvents] called without matching -beginIgnoringInteractionEvents. Ignoring.
What on earth is going on? If I comment out the stopWobble animation, it's fine, but naturally my animations don't stop. If I remove the "UIViewAnimationOptionAllowUserInteraction" option when I begin the animation, I get the beginIgnoringInteractionEvents warning, but this is also no good because I need to interact with these views while they wobble.
The behaviour works fine, so should I just ignore this? Seems to me like something I should fix, if only I can find out what causes it.
Try adding UIViewAnimationOptionAllowUserInteraction to stopWobble. I've gotten that error message before and it seems to have to do with two animations trying to execute simultaneously when they are not explicitly set to do so. Adding UIViewAnimationOptionAllowUserInteraction to my second animation fixed this problem for me.
I guess it happens when you have too many views that will animated at the same time, like a grid of custom views in viewDidAppear.
a. Under iOS4 they all try to disable UIApplication interactions at the same time and to avoid problems UIApplication overflows and ignores some of them.
b. After animating all views tell again UIApplication to enable interactions but UIApplication doesn't recognize some of the enable calls as they were ignored in (a).

Resources