#ios

Show search button on safari keyboard in html

by

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 not playing any sound

by

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

Use AVAudioPlayer to play sound effects

by

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

Sort an array of string containing numbers

by

By default, Sorting an array of string containing numbers is not sorted in natural order of numbers. They are sorted in natural order of string characters.

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

inputAccessoryView ignores bottom Safe Area in iPhone X's

by

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

Auto sizing UICollectionViewCell of UICollectionView fails in iOS 12

by

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

Blurry Pixel Font in SpriteKit bug

by

It's amazing how modern Pixel Art captures the true simplicity yet also expressing creative masterpieces. I find so much solace staring at the world presented by games like Stardew Valley and Kynseed.

In my spare time I am making 2d pixel art game for iOS and macOS for my hobby. I found a free pixel art font called PixelDigivolve to use it for my texts. There was this behaviour that caught my attention where font was being rendered very blurry. The edges were not sharp.

SpriteKit has filtering mode called nearest-neighbour for rendering textures.

CONTINUE READING

Sort NSArray of custom objects with more nesting

by

Sorting an array of custom objects is fair simple. NSSortDescriptor works awesome for this. Lets see an example:


@interface Parent : NSObject
@property(strong, nonatomic) NSString *name;
@end
NSArray *arrayOfParents = @[parent1, parent2];

If I want to sort array of parents by their name then I would use something like:

CONTINUE READING

drawViewHierarchyInRect vs renderInContext

by

I came across very curious problem whose cause I couldn’t have come to know about it without serious debugging because this was something that didn’t catch my attention. I had a task that required capturing snapshot of UIView with hierarchy of subviews and perform few interactive transformation animations on view immediately after - giving feeling of instant multitask. Delay should have been negligent for naked eyes or tolerant but it wasn’t.

CONTINUE READING

Recommended posts