1. Initialize the two rectangles required for the starting and ending
positions for the image in line 4.
2. Add the image to the NSImageView that will be moved back and
forth between these locations in line 5.
3. Add this NSImageView to the BaseView so that we can see the action
in line 6.
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initializeFramePositions];
[self addImageToSubview];
[self addSubview:mover];
}
return self;
}
You will also need to override the following two methods to handle keyboard
events:
- (BOOL)acceptsFirstResponder {
return YES;
}
- (void)keyDown:(NSEvent *)event {
[self move];
}
Returning YES from the acceptsFirstResponder method allows this view to
be the first Responder in the responder chain, and thus it will get the
first chance to respond to the key press events.
Setting the Beginning and Ending Positions
-(void)initializeFramePositions {
CGFloat frameX = NSWidth([self frame]);
CGFloat frameY = NSHeight([self frame]);
leftFramePosition = NSMakeRect(0.0f, 0.0f, frameX /4.0f,frameY / 4.0f);
rightFramePosition = NSMakeRect(7.0f * frameX / 8.0f,
7.0f *frameY / 16.0f,frameX / 8.0f, frameY/ 8.0f);
mover = [[NSImageView alloc] initWithFrame:leftFramePosition];
isRight = NO;
}
-(void)addImageToSubview {
[mover setImageScaling:NSScaleToFit];
[mover setImage:[NSImage imageNamed:@"photo.jpg" ]];
}
initializeFramePositions
Initialize the two rectangles required for the starting and ending
positions for the image
Moving the Image
- (void)move {
if(isRight) {
[mover setFrame:leftFramePosition];
} else {
[mover setFrame:rightFramePosition];
}
isRight = !isRight;
}
写道
You just saw an application that moved a view around without any
animation.
分享到:
相关推荐
You wanted to know how to draw a bitmap to the screen, without the black part of the image covering up what's behind it. You wanted simple animation and more uses for blending. This tutorial will ...
Sprite Kit, a new framework introduced in iOS7, has been designed as a built-in animation workflow for keyframing 2D animation without the need of engines such as Unity to serve as an intermediate....
I accomplished the animation of the firemonkey and the moving ground bar by just using two frames and doing TBitmap.Assign() between them which is not at all the best way to do it but it works for a ...
graphic workspace, without the burden of mastering complicated language definitions and opaque examples. What this book covers Chapter 1, Start your Engines: This chapter explains how to acquire and ...
By moving more tasks onto the quickly evolving GPUs, the number of draw calls per frame can be increased. The chapter gives also an in-depth view on the latest AMD GPUs. “A WebGL Globe Rendering ...
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors ...
Creating a Metal Application in Xcode (without Using a Template) 25 Creating a MTLDevice 28 Creating a CAMetalLayer 28 Creating a Vertex Buffer 29 A First Look at Shaders 31 Libraries, Functions, and ...
9.8.1 Forces without a Velocity Component 479 9.8.2 Forces with a Velocity Component 480 9.8.3 Simulating Drag in the System 481 9.8.4 Leap Frog Method 481 9.8.5 Velocity Verlet Method 483 9.8.6 ...
Q513198 - Moving focus to TcxDBSpinEdit placed in TdxBarControlContainerItem does not fire the OnExit and OnEnter events and, as a result, does not fire the OnGetText event of a dataset field bound to...
Q513198 - Moving focus to TcxDBSpinEdit placed in TdxBarControlContainerItem does not fire the OnExit and OnEnter events and, as a result, does not fire the OnGetText event of a dataset field bound to...
********************************************************************** Author: TMS Software ...1996-2014 ...********************************************************************** TMS Pack for FireMonkey ...
Blueprints are a powerful tool for non-programmers to create complex game logic without writing code. They use a node-based interface for defining behavior. - **The Blueprint Window**: This is where ...
Sometimes both were painted without any data. + to load old Hiedit templates as RTF code use the formatstring -HiEditFields. This will create merge fields for ALL fields. - NL sign was not shown ...