Manipulating iOS keypad on html form

While working with search input in html form I came across steps of information that helped me manipulate iOS keypad. What do I mean by manipulating iOS keypad? It doesn’t mean changing anything about core physical appearance or device capability of software keyboard or device.

I have three requirements for when keypad is up when html input element is active:
  • Search should be the text over return/action button
  • When I press Search on keypad then action should take place or some event should fire off without redirecting or refreshing the page.
  • Lastly when I press ‘Search’ then keypad should also go down or dismissed.

CONTINUE READING

AVAudioPlayer is not playing sound

The most common culprit causing AVAudioPlayer not playing sound is ARC. When my audio player's scope is just within a function ARC deallocates the memory before playing sound after function is called. Here is an example code:


func playSoundEffect(assetName: string?) {
    if let sound = assetName{
        if let asset = NSDataAsset(name:sound){
            
            do {
                // Use NSDataAsset's data property to access the audio file stored in Sound.
                let soundEffect = try AVAudioPlayer(data:asset.data, fileTypeHint:"wav")
                // Play the above sound file.
                soundEffect?.play()
            } catch let error as NSError {
                print(error.localizedDescription)
            }
        }
    }
}

CONTINUE READING

Playing sound effects with AVAudioPlayer

Right now I am at the stage where I am writing foundation to manage my sound effects and background music for my upcoming game. I found two most popular way to play sound effects in SpriteKit:

  • SKAction
  • AVAudioPlayer

After using both I found myself more flexible and comfortable with AVAudioPlayer for following reasons that I am grabbing from Apple’s documentation but it helds true:

Using an audio player you can:
  • Play sounds of any duration
  • Play sounds from files or memory buffers
  • Loop sounds
  • Play multiple sounds simultaneously, one sound per audio player, with precise synchronization
  • Control relative playback level, stereo positioning, and playback rate for each sound you are playing
  • Seek to a particular point in a sound file, which supports such application features as fast forward and rewind
  • Obtain data you can use for playback-level metering
CONTINUE READING

Sorting array by string literal of numbers

We may have stumbled upon strange sorting behaviour of array based on string literal of number where sorting order isn't based on number's value but the alphabetical order.

For example objects in array have property of type string which are all literal of numbers:


slot1.indexStr = “1”
slot2.indexStr = “14”
slot3.indexStr = “2”
slots = [slot1, slot2, slot3]


 slots = slots.sorted { $0.indexStr! < $1.indexStr! }

 1
 14
 2
 

It sorted alphabetically based on first character of string. What we want is to sort based on values of number.

CONTINUE READING

Hiking Satyavati Taal

Our hike started from Sisne Khola. It’s few meters after or before Jhumsa Bridge if you are coming from Butwal or Tansen. There is a message board with direction too but in Nepali language so if you are a foreigner you could ask tea houses. They will guide you to the start of trail.

Trail is very easy to identify because mostly they are of stones so very hard to get lost. Kinda stairs made of stone. We followed it. First half of trails passes through forest. After forest we met off-road dirt path for small vehicles. Don’t follow it. Trail made of stones is just across the road and follow that. You want to hike through nature not dusty road.

CONTINUE READING

Hiking Ranimahal or Ranighat Palace in Palpa

This weekend I did a short hike to Ranimahal or Ranighat palace located in the banks of Kali Gandaki River. My first time visit to Ranighat was in Jeep vehicle. Journey was very unpleasant due to bumpy and dusty road so have your expectations set accordingly. Near the end of road trip - view of Ranimahal from distant was spectacular with river valley behind and river flowing nearby the banks. Landscape was picturesque. The insides are vacant. Once again don’t have your expectations too up. There isn’t much to the architecture of interiors that could be praised about.

Later I found information on short hiking route/trail to Ranighat. This peaked my interest. What Ranimahal lacks in interiors is compensated by the beautiful landscape around it. I planned the hike with my cousin. The hiking journey was memorable where we passed through clean rustic villages, corn fields, green slopes of hills, lush green forests, lots of creeks and small waterfalls. There were countless small creeks and streams on the trails. I could feel the nature and that is the experience all hikers needs.

CONTINUE READING

I bought a new camera

Photography and vlogging is my recent new hobby and the craft I am learning. Primary reason behind this new found interest is because I want to capture my hiking and outdoor travels other than my eyes. I want to share the experience with people.

Flower of a Coriander

Secondary reason is mental exercise that I recieve in a good way. I am from the field of software engineering and if you may believe or not it requires creativity to solve problems which is the most important skills required in any form of engineering. It’s an art too. No wonder why there are less good engineers among many in saturated market here. I learn new skills whether it is related to my work or if it is a new hobby. It keeps the flow of neurone active and sharp.

Remember new hobbies can be expensive in your wallet based on what hobby you choose so tread carefully and plan.

CONTINUE READING

inputAccessoryView ignores bottom Safe Area in iPhone X's

I have this neat view controller setup for my comments system. At the bottom of the screen is inputAccessoryView which will be fixed until interacted with to bring keypad up for user to post comments. When keypad is up view will be above it and if keypad is dismissed then view will stick at the bottom of screen.

To achieve this I override two methods of my UIViewController:


-(BOOL)canBecomeFirstResponder{
    return YES;
}

-(UIView *)inputAccessoryView{
    return commentInputView.contentView;
}

I am using custom xib and my custom input view is composed within the class.

It works fine except in iPhone with notch.

CONTINUE READING

Weekend hiking to Doban via Nuwakot from Butwal

nuwakot-doban trail

This weekend I decided to go doban and stretch some extra kilo metres to my daily hike. My daily trail extends upto 5 km uphill and back downhill isn’t a big stress, credits to the fresh air, smoky mountains and chirping of birds that are enough to heal my body and soul.

I decided to backpack for the weekend hike to cover small settlement called Doban beside Tinau river.

There is an official short hike trail from near Fulbari zoo in Butwal. Tourist and locals use it. I wanted to walk along the peak of hills and embrace the scenic beauty from top. Hence I took long path instead. Nuwakot village was my first destination from where Doban was 3 Km downhill. I started my journey from northwest outskirts of Butwal city, somewhere between Belbas and Jeetgadhi.

CONTINUE READING

Failed Automatic Size of UICollectionViewCell in iOS 12

The content of my UICollectionView flows in horizontal direction. Height of items are fixed but width of each are dynamic based on the length of text. For this example I am using only UILabel in my UICollectionViewCell. My UICollectionViewCell is custom xib.

These are the constraints I have applied to UILabel:
  • Leading : 0
  • Trailing : 0
  • Top : 0
  • Height : 44

CONTINUE READING
Older posts