Abusing UIKit for Gaming in Xamarin.iOS, Part 2: Using Custom Fonts

This is the second in a series of Abusing UIKit blog posts giving some background on the development that want into producing Smudges, a simple game written entirely in Xamarin.iOS where fun shapes in various colors show up on the screen wherever a tap is detected. It was original created to give my two-year-old something fun to play while going tap-crazy on the screen. The game evolved from those “play-testing” sessions. If you have your own little ones and want something fun to distract them, Smudges is availabe on the App Store. At this point, I plan to continue adding features to it as I can. Let me know what you think about Smudges, or these blog posts, in the comments below or find @patridgedev on Twitter. Using an Icon Font Using an icon font can be great for a typical app for substituting a mess of PNGs. For icons, the size savings is probably minimal, but dealing with a single font file compared to a folder of icon images in numerous DPI variations can be much nicer. Since we are dealing with “plain” text in a label, color is controlled by manipulating the label’s text color. For Smudges, the… Continue reading

Abusing UIKit for Gaming in Xamarin.iOS, Part 1: Detecting Taps and Placing Views with UITapGestureRecognizer

This is the first in a series of Abusing UIKit blog posts giving some background on the development that want into producing Smudges, a simple game written entirely in Xamarin.iOS where fun shapes in various colors show up on the screen wherever a tap is detected. It was original created to give my two-year-old something fun to play while going tap-crazy on the screen. The game evolved from those “play-testing” sessions. If you have your own little ones and want something fun to distract them, Smudges is availabe on the App Store. At this point, I plan to continue adding features to it as I can. Let me know what you think about Smudges, or these blog posts, in the comments below or find @patridgedev on Twitter. Where Did They Touch? Smudges has a simple game mechanic: tap the screen, new shape appears. The first step is figuring out when and where a tap occurred. The simple approach is to put a UIButton where you need to detect a touch, attaching a handler to its TouchUpInside event. UIButton someButton = new UIButton(someFrameRectangle); AddSubview(someButton); someButton.TouchUpInside += (sender, e) => { Debug.WriteLine(“Touched somewhere on this button.”); }; Of course, while incredibly simple,… Continue reading

Capturing Your iOS App in Animated GIF Glory

Showing the coolness of your iOS app in a web format can be very difficult, depending on what about your app makes it shine. If your app thrives on animation, especially the new UIKit Dynamics fun, you will need more than one frame to portray what your app does: enter the animated GIF, mother of all awesomeness. Here is the method I used to make the images for my Xamarin UIGravityBehavior recipe. That said, if you know a better way to do this, toss a comment out there; I’d love to hear about it. While I use these methods for my Xamarin.iOS creations, they apply equally to native apps and most anything running on a Mac. The Tool: LICEcap While the name sounds slightly…off, it definitely gets the job done. LICEcap, from Cockos Incorporated, is a quick disk image install. In fact, here’s LICEcap’s capture of me installing LICEcap. One thing to notice, these GIFs are not a great way to capture complex color palettes like the gradients in the install image folder. There may be a tool that is better at that, but you will probably compromise file size for fidelity. That install GIF was 81kb. Capturing the iOS… Continue reading

Xamarin.iOS C# Recipe: Animating Views with iOS 7 UIGravityBehavior (UIKit Dynamics)

Now that iOS 7 has landed, and Xamarin gave us same-day C# support, it’s time to start poking at the new bits. One such piece is UIKit Dynamics. With UIKit Dynamics, you can greatly simplify all sorts of view animations. While this simple recipe will only address UIGravityBehavior, iOS 7 adds a bunch of other predefined behaviors and allows the creation of custom ones as well. Source code is available on GitHub. Basic Gravity Animation To have a view simply start falling off the screen, you just toss the desired view at a new UIGravityBehavior and add that behavior to a UIDynamicAnimator. UIDynamicAnimator animator; public override void ViewDidLoad() { base.ViewDidLoad(); View.BackgroundColor = UIColor.White; animator = new UIDynamicAnimator(View); var item = new UIView(new RectangleF(new PointF(50f, 0f), new SizeF(50f, 50f))) { BackgroundColor = UIColor.Blue, }; View.Add(item); UIGravityBehavior gravity = new UIGravityBehavior(item); animator.AddBehavior(gravity); } You can continue to put items under the effect of gravity by adding them to the behavior. gravity.AddItem(someOtherView); That’s really it for basic gravity, but craziness is only a step beyond that. You can modify the Angle, GravityDirection, and Magnitude of your gravity as well. Potential Memory/Performance Trap It’s worth noting that those items that go flying off the… Continue reading

Making MonoDevelop for Mac (or Xamarin Studio) more like Visual Studio

If I were only living in the land of MonoDevelop, I probably wouldn’t care. I stil spend a large amount of time using Visual Studio, though, and switching contexts becomes very difficult when the IDEs are so different. While I haven’t gone as far as to swap the command and alt keys to match keyboard behavior on Windows, I do try to unite things as much as possible. If you are simply looking for a list of the default MonoDevelop keyboard shortcuts to learn, check out something more like this post from Dan Quirk. [Note: Most of these things apply to Xamarin Studio as well.] Text editing Word break mode This made the biggest difference in my tolerance for MonoDevelop. The default word break mode tends to ignore whitespace, making it behave completely differently moving the cursor forward versus backward in text. Preferences->Text Editor->Behavior; Navigation->Word break mode; set to SharpDevelop. This will bring your option+left/right and option+backspace/delete calls to be more in line with the ctrl versions under Visual Studio. The emacs version looks like it would work, but I opted for SharpDevelop. Key bindings ctrl+Space Bring up contextual menu for Intellisense (Edit.CompleteWord in VS, “Show Completion Window” in MD)…. Continue reading