Cocoa developers were treated to a nice Interface Builder makeover in version 3. One effect we’ve all been admiring is the morphing animation when dragging an item from the Library palette onto a window. It’s actually not too hard and just takes a little showmanship. I’ll show you how it’s done.

The source code and demo app have been moved to their own page.

The Drag Show

Drag Show

The video says it all. Beautiful, isn’t it? I wept a little. Don’t think I didn’t notice the ironic placement of the play arrow, either. No, I didn’t plan that but I’m happy to take credit for it if you’re so inclined.

Beglittered Cocoa

By the way, Cocoa is a drag queen’s name if ever there was one, isn’t it? To quote a statistic I made up just now, a full 51% of all drag queens are named “Cocoa”. If we’re to keep our girl looking fabulous, we need to update her look regularly.

Why “beglitter” our hammers and saws (and Interface Builders) when the things we build aren’t getting at least as good a treatment? Simply put, basic drag and drop is dreadfully plain. As in “give-her-a-credit-card-and-send-her-to-Macy’s-the-poor-thing” plain. Honey, it’s more worn out than Vanna White’s pumps, m’kay?

I digress. Let’s look at how Interface Builder does it.

Interface Builder’s Routine

With Interface Builder’s Library palette, as long as the item being dragged from the palette is still within the palette’s bounds, the item is represented with its icon image (the representation used in the collection view that contains all the available library items). Once it’s dragged out of the palette, however, it morphs into the size and shape it will be when the object is instantiated (well, in the case of a control dragged to a window, that is).

Usability Considerations

While IB’s approach is mostly eye candy, it solves two problems. First, the control can’t stay an icon because it gives you no visual context regarding what happens when you drop it into a subview. Second, the dragged item can’t immediately become the control (with no animation), because it’d be confusing when you’re suddenly “holding” a very-different-looking item than you “picked up”. It’d be like reaching out and grabbing a marshmallow peep only to find yourself holding a very real (and very pissed off) python. Bewildering.

Outside IB, however, there’s a far sweeter prize I’ve been eyeing personally. Consider a library of objects (a list of items with a small icon and a title when dragged). The library can be reordered and reorganized via drag and drop. What if you want to add promised file drags so the item creates a file when dragged out of the app and onto the desktop or a folder? Imagine the dragged item (still looking like a list item in the library view) morphs into an appropriate document icon when it leaves the window? Now we’re talking!

I’m sure there are other scenarios that could benefit from this kind of UI feedback. Let’s examine how this could be achieved with a little showmanship.

A Possible Approach

The problem with Cocoa’s dragging mechanism is that it takes a single, static image as the representation of the dragged item. There’s no supported way to modify this image mid-drag, nor is it possible to animate anything. But that’s not entirely necessary.

It’s important to note how much good Cocoa UI glitz is really mostly trickery (or can be). Overlay windows are commonly used for various effects (Interface Builder uses them in several places that I can see, or maybe it’s just one big one that handles all the effects). I started daydreaming about how a borderless, transparent window could achieve this.

The window would use basic view animation (not necessarily Core Animation) to morph between the two images. When the drag begins, this window would take the place of the dragging image, following the pointer around as the drag progresses. We just have to find a way to keep the existing drag mechanism but ditch the static image.

It turns out that’s not so difficult. You’re not allowed to pass nil as the image, so we just give it an empty one. It doesn’t really like a zero-sized image (it complains it can’t lock focus on the image), so we give it one with a size of 1×1. There’s one more snag – if you let the drag and drop mechanism perform a slide-back, you have to wait for it to finish before being notified the drag has ended. This would cause a slight delay before we’d know to perform our own slide-back routine with our prettier solution.

That leaves the animation of the “morphing” effect. If you look closely (i.e., obsessively play with Interface Builder until your eyes bleed), you’ll see that all it’s doing is animating the size and cross-fade. This is easy with Cocoa. Mostly. To do this requires two image views (for the inside and outside images) and some careful choreography.

Reusability

Let’s take a moment to consider this. I expect to use this effect in all my new applications, but I’m lazy. I want one self-contained class. I want to start it up with one line of code and manipulate it with a bare minimum of interaction.

To this end, the first requirement is that it be a singleton. I don’t feel like fussing over it, maintaining it, disposing of it, etc. Since the user can effectively only perform one drag session at a time (for now), only one instance is ever needed per app.

The second requirement is that it should have, at most, the same number of “drag and drop interaction” methods the drag and drop protocol itself provides: start, update position, and finish.

The third is flexibility. In addition to its standard ability to remember its starting point, I wanted to allow it to designate any rectangle on the screen (as in “screen coordinates”) as its “inside” area. This gives us the ability to specify a part of a view, a whole view, a window, or even an entire screen as the inside area. In the future, I might even like to use different transition effects. That’s for another time but the design lends itself to that change fairly easily. I just ran out of time.

The only negative mark (for the cause of laziness) is that it uses QuartzCore (for customizing the animation). Because of this, you have to remember to link against the QuartzCore framework in your target.

I even managed to do all this without becoming a private API skank!

Note: I know what you’re thinking and no, I would make a terrible drag queen. I certainly have attitude but I have a feeling I’d be a train wreck in heels and mascara …

Have Fun!

The source, license, and a code snippet are available on the JLNDragEffectManager page.

Real-World Example

Update: See a real-world example in XTabulator 2 (drag-rows-to-desktop-to-make-a-file-of-those-rows).

 

XTabulator 2.001 is now available. The update is free to all 2.x users and is available by direct download from the web site or through the software’s automatic update system.

Changes:

  • Fixed a bug that prevented the column action button from appearing correctly when scrolling the table horizontally.
  • Made corrections and clarifications to the Help Book.

Send feedback or questions to support@bartastechnologies.com!

 

Ah, iStockphoto. They bother me. They really do. Their “credits” system – a throwback to carnival days – is just plain hostile toward consumers and only benefits them. Why do consumers support businesses that use these systems?

LOL Cat says: "DO NOT WANT"

I’ve used iStockphoto on occasion over the last few years for vector artwork for Bartas Technologies’ products and web site. I’ve been increasingly annoyed by the inconvenience of actually buying stuff from them. Recently, however, I was told my credits would expire if I didn’t use them soon. This lead me to really think about what I was doing by giving my money to this company.

Here is my specific gripe: You must purchase credits in blocks (like 10, 100, etc.). Artwork is priced such that it’s never evenly-numbered, always leaving unused credits when you make one-off purchases. Credits inexplicably “expire” after one year if you do not use them.

As I mentioned, this type of system is not new. In fact it’s very old and not at all tied to technology. It’s been used in carnivals for a long time and likely elsewhere. You give them real money and they give you a certain usually-even number of credits (maybe in the form of tickets). Once inside, you find nothing costs an even number of tickets. You could purchase more to make up the difference but you always find yourself leaving with unused (and unusable) tickets. This serves several purposes: It obfuscates the real cost of rides, games, food, and more, making it difficult to judge your spending and making you more inclined to hand over this worthless little piece of paper than you would be with actual cash. It ensures you’ll have to buy large quantities of credits in order to fully use them all (assuming the pricing structure isn’t rigged so this is never possible, which it often is).

This kind of system only benefits the business. It has zero benefit for the customer and in fact is customer-hostile. It’s a barrier to quick and easy purchase, it restricts choice, purposely makes it difficult to judge spending, and is structured toward pressuring you into buying more to avoid losing money you’d already given them.

It’s all so disgusting.

There have been plenty of times when I would have purchased something from iStockphoto if I weren’t forced to deal with this credits-based system. Now, since I have no need of any artwork between now and the time they said my credits will expire (I currently have exactly 1 less credit than the usual price of vector artwork of sufficient quality), it looks like I’ll lose that money.

Why?

There’s no valid technical reason why these credits should expire. There’s no business case for expiration either. The only party this serves is iStockphoto, at the expense of its customers. When you add that to the fact that the copyright holders only get a few cents per purchase, I’m so thoroughly disgusted by this company, I’m no longer willing to give them my hard-earned money. To call it a rip-off is perhaps unfair – if you don’t agree to the terms, don’t buy their credits – but I think consumers need to send this message to businesses like iStockphoto by going with competitors that don’t resort to this customer-hostile tactic.

 

Someone asked me how to add visual elements to a text field. This someone had several ideas that were “creative” but bat-shit nuts. I’m always hesitant to “give a man a fish” but figured the example I was thinking of was not only a good lesson to Cocoa newbies but a useful bit of code for others to use. It’s a text field cell subclass that draws “total bars” top and/or bottom in several styles and in any color.

The total bar cell can be used in a table, or in a label, in a house, or with a mouse. You can use it free of charge, I’d just like credit, by and large. See the license before you use it, or my friend, I just may lose it …

Have Fun!

The source, license, and a code snippet are available on the JLNTotalBarTextCell page.

 

Friends, family, customers, and co-workers have all asked me when I’m going to develop an iPhone application. For a time, my answer was, “when I come up with a good idea.” Now my answer is, “when Apple changes its attitude.”

No Idea Whatsoever

Let me explain my earlier response. I’m not the kind of guy that creates solutions then looks for problems to which to apply them. For me, the idea of sitting and dreaming up a software application for the iPhone for the sake of developing an application for the iPhone is silly. My best ideas come from existing problems with no solutions that are adequate for my needs, or for the needs I suspect others would have. In the case of the iPhone just couldn’t think of any such problems that either hadn’t already been done well (or a thousand different ways) or would be permitted by Apple’s strict control of the platform. This latter realization slowly morphed into my latest stock response.

Bad Attitude

I understand Apple’s desire to control the platform. A consistent spread of poorly-written applications with poor, crashy performance reflects upon the iPhone in most consumer’s minds. What I don’t understand is the myriad other issues that make developing for the platform unsatisfying and outright risky for any serious developer with any desire to run a lasting, stable business. Let me count the ways …

One, One-Thousand – ‘Ware the Troll

As a desktop software publisher, the Internet has empowered me to spend my time pursuing a vision in which I truly believe. A problem-solver application about which I am passionate (because I had a problem I knew others had as well). At the end of each new application, I am always excited (and a little frightened) about the prospect of launching. There’s always a mix of praise and hate-mail (“great app! you nailed it!” and “you suck! not ready for prime-time!“), but the experience is always rewarding. Why? Because it usually goes very well and, more importantly, nobody is standing between me and launching my product. When and whether or not to launch is in my control. I’m the author. It’s my business, my product. If I were to develop a product for the iPhone platform, however, my months of labor could be rendered pointless by the proverbial bridge troll.

Imagine, if you will …

An eager merchant, I traipse down the golden path, proudly pushing my cart full of wares toward the mythical city of AppStore. My head is full of dreams of the fabled marketplace and I’m certain – so certain – my wares are irresistible. I’m humming a happy tune as I approach the bridge when suddenly a shiny aluminum-and-glass troll pops out, gnarly and rude.

“This be my bridge!” the troll exclaims. “Ye cannot pass!”

Try as I might, I can’t convince the troll to let me pass. His reasoning ranges anywhere from quality to a potential conflict with something he himself may want to build. Perhaps he’s decided small children could spell “boobies” by typing 5318008 and turning the device upside-down, the poor dears. Crestfallen, I must turn my cart around and go home. Nobody will buy my wares now. The twinkling lights of the AppStore at my back, I return to my hovel to mourn the passing of my dream.

… and scene.

In the interest of saving the drama fo’ yo’ mamma, I’ll get to my point: being stopped by the Apple Bridge Troll is not only possible, but likely enough to be an unacceptable business risk. I’m not a high school kid with “nothin’ but time” – I’m a working adult with 50+ hours divided among some pretty serious duties, not even considering personal and family time. I just can’t invest the time it takes to create a good, solid software product, only to be shut down by a bitchy troll.

Two, One-Thousand – No Dinner, No Movie

To make matters worse, you’re not selling your application. Apple is. Customers who buy your app belong to Apple, not you. You have no say in refunds, discounts, upgrade policies, technical support management, promotions, conflict resolution, unfair reviews, nor even pricing (due to precedent set by Apple).

If I’m going to be screwed, the least my suitor could do is buy me dinner and a movie first. Make the attempt. Woo me. Make me at least think I might want it, maybe. At a bare minimum, give me beer goggles and something for the pain …

Three, One-Thousand – THINK OF THE CHILDREN!

Point-blank: Apple’s censorship policies are absurd. So absurd as to be an industry joke. A sad one, sure, but a joke nonetheless. Apple’s reviewers – whoever they are – are inconsistent, intolerant, inflexible automatons who deserve every bit of ire they’ve drawn.

An e-book reader specializing in old texts was banned because it could be used to search the Kama Sutra … a version without pictures that suggests rubbing your dick with the bristles of some insect to improve it somehow (I didn’t read the details). Here’s some news for you: So can any web browser. Interestingly, there’s ample proof all over the web that these parental control filters just don’t work. Kids who are old enough to even understand such a text are smart enough to use one of the many methods of bypassing such filters.

Let’s leave alone the fact that it’s not our computer’s job to raise our children. It’s ours. The humans. The people who should be monitoring these things. If something like the text from the Kama Sutra falling into your child’s hands worries you, why in the screaming depths of hell are you allowing your children unsupervised access to the Internet anyway? If little Billy is pulling his pudd to ancient textual advice on sex, be thankful – there’s some really sick shit out there in picture and movie form the Kama Sutra doesn’t even approach. Which would you prefer he access? The alternative is to make little Billy a eunuch. I digress.

Apple should definitely provide basic security for parents to block casual attempts at “smut”, but that’s where it should end. Any attempts beyond casual indicate the need for the parent to step in, not for Apple to work harder to nanny their wayward young at the expense of good software.

Four, One-Thousand – Hurry Up and Wait

The review process itself, clearly, leaves a lot to be desired. To add insult to injury, it takes far too long. This is bad for initial releases as well as updates if you’re the type of developer who likes to be communicative about your progress. This makes timing your marketing just about impossible. That’s it. No snarky quip.

Conclusion

Until Apple changes its attitude toward the developers who work so hard to give its platform the universal appeal it now enjoys, the iPhone platform simply isn’t attractive to me. Others have jumped right to calling it “hostile toward developers”. I agree. Plenty of well-known Mac developers have quit the platform entirely. I have better things to do, too. Bartas Technologies (or even Joshua Nozzi) won’t be investing the time or money (unless someone else is paying for it) in this platform any time soon, it seems. I’ll stick to the Mac desktop platform.

 

So I finally did it. I pushed the big red Deploy button and released XTabulator 2. Okay, there is no big red Deploy button in reality, but there’s one in my head. And I pushed it. And damn, did it ever feel good.

As I mentioned previously, XTabulator 2 is a much-needed rewrite that almost didn’t happen because I’d originally sold the rights to this application to Apokalypse Software. Unfortunately (or is it?) that contract did not go well. At all.

XTabulator Product Page

Rather than throw it back up onto my site with no improvements (or adding a few features and bug fixes), I thought it best to offer a brand new, modern version. It has a lot of polish and plenty of potential for added features. Its focus is simplicity for the most common tasks (and formats: CSV/TAB). It’s lightweight and fast. It requires Mac OS X 10.5 or above and works on PowerPC or Intel Macs (ie, it’s a Universal Binary). A full license costs $19.99 (for now) and owners of version 1 can upgrade for half price. (Apokalypse customers, please see the appropriately-titled section below before purchasing.)

Some Clarifications

A lot of people have sent in some very helpful feedback. Thanks! One recurring theme, however, is that of what makes “delimited data files”. Here are some clarifications I think may help:

  • CSV means “comma-separated values”. Those programs that export a file with a .csv extension but use semicolons are wrong. If you promise XTabulator a CSV file (via a .csv extension), you must give it a comma-separated file. :-) The same goes for “.tab” (the delimiter is a tab character and nothing else).
  • Related to the first point, if you have a “something-else-delimited” data set, give it an extension of anything but “.csv” or “.tab” and you should have no problems.
  • Several different kinds of delimiter character within the same file is a custom file format. XTabulator does not handle custom file formats.
  • Files that contain anything but delimited data records (one record per line, fields separated by the designated delimiter) are a custom file format. Again, XTabulator does not handle custom file formats.
  • For now, XTabulator focuses on a “something-delimited” data set. Fixed-width fields are not supported at this time. Note all the marketing blurbs mention “delimited data files”. This is no accident. :-)

Apokalypse Customers

As an apology to those who purchased version 1 directly from Apokalypse, I’m giving this upgrade away to those customers free of charge. Those customers have already been e-mailed directly with a free, personalized upgrade coupon code. If you are one of those customers but did not receive this e-mail, please contact support@bartastechnologies.com for your coupon.

Why the Hold-Up

Some of you are probably wondering “why the hold-up?” Well, I have a fairly busy life. I, like anybody else, work best when I’m not burned out. In reality, I could have launched a month ago if I worked myself to the bone. As you may know, I have a full-time job as well as a family life. I took my sweet time with the marketing and web site work and feel just fine about that fact.

You know what I did most of the time I could’ve been pushing hard to finish this release? Reading. Yes, that’s right. Reading. Several thousand pages of some very nice fiction. Some TV, but mostly reading. On the couch, in the tub, on the deck, and here’s the rub: I’m not sorry. :-)

In Closing

As always, if you have any suggestions, bug reports, or any kind of feedback at all, let me know (through the Bartas contact info, please – no Bartas-related mail to my personal e-mail address, thanks).

© 2011 Joshua NozziJoshua Nozzi is a Cocoa developer for hire.Suffusion theme by Sayontan Sinha