Example: The Icon Shuffle
This example creates four icons on the screen and allows the user to move them around freely, either individually or two at a time using a gesture. This illustrates the use of various geometry structures and functions, event notifications, and Graphics Services functions. To pick up an icon, tap and hold it, move it where it should go, then release your finger. If the status bar is tapped, the icons are reset to their original positions.
To compile this example from the command line, you'll need to use several different frameworks: Core Graphics, Graphics Services, and UIKit, in addition to the foundation frameworks:
$ arm-apple-darwin-gcc -o MyExample MyExample.m -lobjc \
-framework CoreFoundation -framework Foundation \
-framework UIKit -framework CoreGraphics \
-framework GraphicsServices
Example 4-1 and Example 4-2 contain the header file and executable methods for the example.
Example 4-1. Mouse and gesture example (MyExample.h)
#import <CoreFoundation/CoreFoundation.h> #import <UIKit/UIKit.h> #import <UIKit/UITextView.h> @interface MainView : UIView { UIImage *images[4]; CGRect positions[4]; CGPoint offsets[4]; int dragLeft, dragRight; } - (id)initWithFrame:(struct CGRect)windowRect; - (void)reInit; - (void)mouseDown: (struct _ _GSEvent *)event; - (void)mouseUp: (struct _ _GSEvent *)event; - (void)mouseDragged: (struct _ _GSEvent *)event; - (void)gestureStarted: (struct _ _GSEvent *)event; - (void)gestureEnded: (struct _ _GSEvent *)event; - (void)gestureChanged: ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access