I have implemented game application.In which i want to animate some area of images on shake effect.How it possible please give me advice.
Edit:
My excatly query is that:
In my game application there is one image.Now i am selected some area frame of image.now i am shaking iphone then only selected area of frame image must be animate.
Here is a skeleton ... then you can get more detail at the suggested docs. This is real simple-minded but has a randomization and you can instantiate with your own image. I created an image container as a UIViewController and in my main (either your AppDelegate or the RootViewController) you create the instance in viewDidLoad. The methods that have to be overloaded in your AppDelegate, (the code is at the end of the post) so it receives shakes, are:
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear
canBecomeFirstResponder
becomeFirstResponder
nextResponder
You become a responder in viewWillAppear and you have to enable the device notifications (verified that there is a documented bug) so the motion methods get invoked.
motionBegan:withEvent
motionEnded:withEvent
I like to put an NSLog(#"%s", FUNCTION); statement in all my first-time written methods, that way I can quickly determine if something is missing to get my events, properly initialized, etc. Its just my style.
AnimatedImage.h isA ViewController
#interface AnimatedImage : UIViewController {
UIImageView *image;
UILabel *label;
float cx;
float cy;
float duration;
float repeat;
}
#property (nonatomic, retain) UIImageView *image;
#property (nonatomic, retain) UILabel *label;
-(id) initWithImageName: (NSString*) imageName;
-(IBAction) shake;
AnimatedImage.m
#include <stdlib.h>
#define random() (arc4random() % ((unsigned)RAND_MAX + 1))
#import "AnimatedImage.h"
#implementation AnimatedImage
#synthesize image;
#synthesize label;
-(id) initWithImageName: (NSString*) imageName {
NSLog(#"%s", __FUNCTION__);
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
return self;
}
-(IBAction) shake {
cx = 0.90 + (random() % 10) / 100; // cx = 0.95;
cy = 0.90 + (random() % 10) / 100; // cy = 0.95;
duration = ( 5.0 + random() % 10) / 1000.0;
repeat = (65.0 + random() % 20);
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, cx, cy);
[UIView beginAnimations: #"identifier" context: #"shake"];
[UIView setAnimationDelegate:image.superclass];
[UIView setAnimationDuration: duration]; // 0.008];
[UIView setAnimationRepeatCount: repeat]; // 85.0];
[UIView setAnimationRepeatAutoreverses: YES];
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
[UIView commitAnimations];
}
-(IBAction) bounce {
image.transform = CGAffineTransformTranslate(image.transform, -20, -6);
[UIView beginAnimations: #"identifier" context: #"bounce"];
[UIView setAnimationDelegate:image.superclass];
[UIView setAnimationDuration: duration];
[UIView setAnimationRepeatCount: repeat];
[UIView setAnimationRepeatAutoreverses: YES];
image.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
[UIView commitAnimations];
}
#end
This "root or main" delegate is a UIViewController. I have left of detail to show its simplicity, but still left my 'trace' code that I find essential for first-time debugging. Also, as an aside, I believe you have to overload motionBegan, even if you only need the motionEnded event. I recall that my app did not work and then I added the motionBegan and it started to call motionEnded. It kinda' makes sense that it would be that way, but I don't have any documentation to back it up. A simple experiment after you get it working can confirm or deny my comment.
- (void)viewDidLoad {
[super viewDidLoad];
[super becomeFirstResponder];
.
.
.
NSLog(#"%s", __FUNCTION__);
NSLog(#"%s: I %s first responder! (%#)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);
.
.<created image in this ViewController's NIB using IB>
.
someImage = (UIImageView *) [self.view viewWithTag:TAG_SOMEIMAGE];
aniImage = [[AnimatedImage alloc] init];
aniImage.image = someImage;
}
-(void) viewWillAppear: (BOOL) animated{
NSLog(#"%s", __FUNCTION__);
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: #selector(receivedRotate:)
name: UIDeviceOrientationDidChangeNotification
object: nil];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(#"%s", __FUNCTION__);
[super becomeFirstResponder];
assert( [self canPerformAction:#selector(motionEnded:withEvent:) withSender:self] );
}
- (void)viewWillDisappear:(BOOL)animated {
NSLog(#"%s", __FUNCTION__);
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver: self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
NSLog(#"%s", __FUNCTION__);
[super resignFirstResponder];
}
- (BOOL)canBecomeFirstResponder {
NSLog(#"%s", __FUNCTION__);
return YES;
}
- (BOOL)becomeFirstResponder {
NSLog(#"%s", __FUNCTION__);
return YES;
}
- (UIResponder *)nextResponder {
NSLog(#"%s", __FUNCTION__);
return [self.view superview];
}
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(#"%s", __FUNCTION__);
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(#"%s", __FUNCTION__);
if( [self isFirstResponder] ) {
[aniImage shake];
}
}
This code does work -- but if I snipped out too much detail, just ask and I will make certain to add enough to help you along. This was a really rewarding task for me and I am excited to share it with someone looking for some help in the same experience.
Have a look at LocateMe example code, one of the first samples in the SDK and use and change the bounce back to centre code.
Related
A UIViewController is called when a user touches an image on a UITableViewCell.
It is called using modalViewController.
On this modalViewController is a UIScrollView, with another UIImageView in the middle, that fetches an image using NSDictionary (passed from the UITableViewCell).
Now, what I wanted to achieve was the ability for the user to drag the image vertically only, such that dragging and releasing a little would cause the image to return to the center with animation. If the user drags it to the extremes, the entire UIScrollView is dismissed and the user returns to the UITableView. I used the following code. The issue here is, and as my name suggests, this code is crude. Is there an elegant way of doing this, without the need of so much calculation?
BOOL imageMoved=NO;
- (void) touchesMoved:(NSSet *)touches
withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
CGRect imageRect = _photoImageView.frame;//_photoImageView object of UIImageView
CGFloat imageHeight = imageRect.size.height;//getting height of the image
CGFloat imageTop=240-imageHeight/2;
CGFloat imageBottom=imageTop+imageHeight;//setting boundaries for getting coordinates of touch.
// Touches that originate above imageTop and below imageBottom are ignored(until touch reaches UIImageView)
if (pos.y>50&&pos.y<430&&pos.y>=imageTop&&pos.y<=imageBottom){//extremes are defined as top and bottom 50 pixels.
imagedMoved=YES;//BOOL variable to hold if the image was dragged or not
NSLog(#"%f", pos.y);
[UIView setAnimationDelay:0];
[UIView animateWithDuration:0.4
animations:^{_photoImageView.frame=CGRectMake(0,pos.y-imageHeight/2,320,200);}
completion:^(BOOL finished){ }];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
if (pos.y>50&&pos.y<430){//if touch has NOT ended in the extreme 50 pixels vertically
[UIView setAnimationDelay:0];//restoring UIImageView to original center with animation
[UIView animateWithDuration:0.4
animations:^{_photoImageView.frame=CGRectMake(0,140,320,200);}
completion:^(BOOL finished){ }];
imagedMoved=NO;//prepare BOOL value for next touch event
}
else if(pos.y<50||pos.y>430)
if(imagedMoved)
[self.photoBrowser exit] ;//exit function(imported from UIScrollViewController) dismisses
//modalView using [self dismissViewControllerAnimated:YES completion:nil];
}
All code here is a modification onto a customized copy of UITapView in MWPhotoBrowser.
Yo, here is a much easier way to do this, more or less an example of what Alessandro stated. I'm not finding the top of the screen but I'm giving the illusion of it.
BCViewController.h
#import <UIKit/UIKit.h>
#interface BCViewController : UIViewController <UIScrollViewDelegate>
#property (weak, nonatomic) IBOutlet UIScrollView *svScroller;
#property (weak, nonatomic) IBOutlet UIImageView *ivFish;
#end
#import "BCViewController.h"
#interface BCViewController (){
UIPanGestureRecognizer *_panGestureRecognizer;
CGPoint _fishOrigin;
}
#end
#implementation BCViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.svScroller.delegate = self;
[self.svScroller setContentSize:self.view.frame.size];
self.svScroller.translatesAutoresizingMaskIntoConstraints = NO;
self.ivFish.userInteractionEnabled = YES;
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanFrom:)];
[self.ivFish addGestureRecognizer:_panGestureRecognizer];
_fishOrigin = self.ivFish.center;
NSLog(#"center %f", self.ivFish.center.x);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)handlePanFrom:(UIPanGestureRecognizer *)recognizer{
// if you want it but not used
CGPoint translation = [recognizer translationInView:recognizer.view];
// if you want it but not used
CGPoint velocity = [recognizer velocityInView:recognizer.view];
CGPoint tempPoint;
if (recognizer.state == UIGestureRecognizerStateBegan) {
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
tempPoint = [recognizer locationInView:self.view];
self.ivFish.center = CGPointMake(175.5, tempPoint.y);
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint tempPoint;
tempPoint = [recognizer locationInView:self.view];
if (tempPoint.y < 132) {
[UIView animateWithDuration:.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^ {
[self.navigationController popViewControllerAnimated:TRUE];
}
completion:NULL];
} else {
[UIView animateWithDuration:.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^ {
self.ivFish.center = _fishOrigin;
}
completion:NULL];
}
}
}
i want to change position of imageview with animation. it just like draw playing card and it will sets to center anyone here who help me for this.
Code-:
#interface PockerAppViewController : UIViewController
{
UIButton *btn;
UIImageView *cards;
}
#property(nonatomic,retain) IBOutlet UIButton *btn;
#property(nonatomic,retain) IBOutlet UIImageView *cards;
-(IBAction)hidebtn:(id)sender;
-(void)setCards;
#end
--------------------------------.mfile-----------------------------
#implementation PockerAppViewController
#synthesize btn,cards;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
cards = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"King.png"]];
//[cards setHidden:TRUE];
}
-(IBAction)hidebtn:(id)sender
{
[btn setHidden:TRUE];
[self setCards];
}
-(void)setCards
{
[cards setFrame:cards.frame];
[UIView beginAnimations:#"Move" context:nil];
[UIView setAnimationDuration:0.3];
[cards setCenter:CGPointMake(60,240)];
[UIView commitAnimations];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint pos = [touch locationInView:touch.view];
NSLog(#"X: %f",pos.x);
NSLog(#"X: %f",pos.y)
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
this is my data it help me to solve this problem..
Try something like this:
[URImageView setFrame:CurrentPositionFrame];
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[URImageView setFrame:ToTheNewPositionFrame];
[UIView commitAnimations];
As Till pointed you can also use the Center property:
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[URImageView setCenter:CGPointMake(nPositionX ,nPositionY)];
[UIView commitAnimations];
Thanks Till.
think this could be helpful
http://www.flashgamehole.com/Tong/play-game/en/
I have an app that I'd like the swipe gesture to flip to a second view. The app is all set up with buttons that work. The swipe gesture though causes a crash ( “EXC_BAD_ACCESS”.).
The gesture code is:
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
switch (recognizer.direction)
{
case (UISwipeGestureRecognizerDirectionRight):
[self performSelector:#selector(flipper:)];
break;
case (UISwipeGestureRecognizerDirectionLeft):
[self performSelector:#selector(flipper:)];
break;
default:
break;
}
}
and "flipper" looks like this:
- (IBAction)flipper:(id)sender {
FlashCardsAppDelegate *mainDelegate = (FlashCardsAppDelegate *)[[UIApplication sharedApplication] delegate];
[mainDelegate flipToFront];
}
flipToBack (and flipToFront) look like this..
- (void)flipToBack {
NSLog(#"%s", __FUNCTION__);
BackViewController *theBackView = [[BackViewController alloc] initWithNibName:#"BackView" bundle:nil];
[self setBackViewController:theBackView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[frontViewController.view removeFromSuperview];
[self.window addSubview:[backViewController view]];
[UIView commitAnimations];
[frontViewController release];
frontViewController = nil;
[theBackView release];
// NSLog (#" FINISHED ");
}
Maybe I'm going about this the wrong way... All ideas are welcome...
Why are you even using performSelector: Just because a method is marked as an (IBAction) doesn't make it any different from any other method, and you can send them as messages to a class instance
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
if ((recognizer.direction == UISwipeGestureRecognizerDirectionRight) || (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)) {
[self flipper:nil]
}
}
Actually, since the gesture directions are just bit flags this can be written as:
- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {
NSLog(#"%s", __FUNCTION__);
if (recognizer.direction & (UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft)) {
[self flipper:nil]
}
}
Your selector needs to take an argument as implied by the : character in the name, so you should use performSelector:withObject:.
[self performSelector:#selector(flipper:) withObject:nil];
OK, I guess my previous question wasn't in detail.
I'm providing more details.
Before posting full source code I have to ask if my question:
My question is Why the following program doesn't call touchesBegan, touchesMoved and touchesEnded? It used to work in previous iOS SDK. My current xcode version is 3.2.5
One comment: The following code dose call all touches if you run it against iPad Simulator. So that's very odd why iPhone simulator and the actual device don't respond to the problem.
main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
[pool release];
return retVal;
}
AppDelegate.h
#import <UIKit/UIKit.h>
#class GLView;
#interface AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow* mp_window;
GLView* mp_viewController;
}
#end
AppDelegate.mm
#import "AppDelegate.h"
#import "GLView.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
mp_window = [[UIWindow alloc] initWithFrame: screenBounds];
mp_viewController = [[GLView alloc] initWithFrame: screenBounds];
[mp_window addSubview: mp_viewController];
[mp_window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{}
- (void)applicationDidBecomeActive:(UIApplication *)application
{}
- (void)applicationWillTerminate:(UIApplication *)application
{}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Handle any background procedures not related to animation here.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Handle any foreground procedures not related to animation here.
}
- (void)dealloc
{
[mp_viewController release];
[mp_window release];
[super dealloc];
}
#end
GLView.h
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>
#interface GLView : UIView <UIAccelerometerDelegate>
{
#private
EAGLContext* mp_context;
}
- (void) gameLoop;
- (void) drawView: (float) interpolation;
- (void)touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
- (void)touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
- (void)touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
- (void)accelerometer: (UIAccelerometer *) accelerometer
didAccelerate: (UIAcceleration *) acceleration;
#end
GLView.mm
#import "GLView.h"
#import <OpenGLES/ES2/gl.h>
#implementation GLView
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id) initWithFrame: (CGRect) frame
{
if (self = [super initWithFrame: frame])
{
CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
eaglLayer.opaque = YES;
EAGLRenderingAPI api = kEAGLRenderingAPIOpenGLES1;
mp_context = [[EAGLContext alloc] initWithAPI: api];
if (!mp_context || ![EAGLContext setCurrentContext: mp_context])
{
[self release];
return nil;
}
[mp_context renderbufferStorage: GL_RENDERBUFFER
fromDrawable: eaglLayer];
//TODO: to setup the size of frame for render
//////
//acc
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(0.1f)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
//multi - touch
[self setUserInteractionEnabled:YES];
[self setMultipleTouchEnabled:YES];
[self performSelectorOnMainThread:#selector(gameLoop)
withObject:nil waitUntilDone:NO];
}
return self;
}
- (void) gameLoop
{
while(1)
{
//Get all touches
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode,
0.002f,
TRUE) == kCFRunLoopRunHandledSource);
//render scene
[drawView 1.0f];
}
}
- (void) drawView: (float) interpolation
{
//TODO: adding render image here
//NSLog(#"Render: %f", interpolation);
[mp_context presentRenderbuffer: GL_RENDERBUFFER];
}
- (void) dealloc
{
if ([EAGLContext currentContext] == mp_context)
[EAGLContext setCurrentContext: nil];
[mp_context release];
//TODO: relese all objects here
[super dealloc];
}
- (void)touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
{
int hash;
CGPoint points;
for(UITouch * touch in touches)
{
hash = [touch hash];
points = [touch locationInView: self];
NSLog(#"Touch Began: %d, %f, %f", hash, points.x, points.y);
}
}
- (void)touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
{
int hash;
CGPoint points;
for(UITouch * touch in touches)
{
hash = [touch hash];
points = [touch locationInView: self];
NSLog(#"Touch Moved: %d, %f, %f", hash, points.x, points.y);
}
}
- (void)touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
{
int hash;
CGPoint points;
for(UITouch * touch in touches)
{
hash = [touch hash];
points = [touch locationInView: self];
NSLog(#"Touch Ended: %d, %f, %f", hash, points.x, points.y);
}
}
- (void) accelerometer: (UIAccelerometer *) accelerometer
didAccelerate: (UIAcceleration *) acceleration
{
NSLog(#"Accelerometer: (%f, %f, %f)",
acceleration.x,
acceleration.y,
acceleration.z );
}
#end
This is only a test case. my main concern is why with new SDK, touches won't be called? Please don't tell me I have to use NSTimer or other timers. I did work before I install the new SDK. I'm just wondering if anyone can see any problem in that source code other than that.
Thanks,
Memphis
I don't know with certainty what your problem is. I do note, however, that you don't have a view controller--while your UIApplicationDelegate subclass has a mp_viewController member, it's a UIView instead of a UIViewController. It is possible that this is the source of your problem.
I suggest adding a UIViewController associated with your view and assigning it to the application delegate's rootViewController property.
I have a short audio clip that plays when a button is pressed. I want to create a slide-up controller from the bottom that contains a pause/play button and a slider bar displaying the length of the audio. I also want the view behind the controller to remain scrollable while the controller is visible. I believe this excludes using a UIAlertView or UIActionSheetView as both cause the view below to remain static. What is the best way to implement this?
EDIT: i found a helpful tutorial here: http://iosdevelopertips.com/user-interface/sliding-views-on-and-off-screen-creating-a-reusable-sliding-message-widget.html
and I was able to modify this to get something of what I want. However, if I would like to animate using a nib file where/how would i call this?
#import "SlidingMessageController.h"
#interface SlidingMessageController(private)
- (void)hideMsg;
#end
#implementation SlidingMessageController
#pragma mark -
#pragma mark Private Methods
- (void)hideMsg;
{
// Slide the view off screen
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
frame.origin.y = 480;
frame.origin.x = 0;
self.frame = frame;
//to autorelease the Msg, define stop selector
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
}
- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context
{
[self removeFromSuperview];
[self release];
}
#pragma mark -
#pragma mark Initialization
- (id)initWithDirection:(int)dir;
//- (id)initWithTitle:(NSString *)title message:(NSString *)msg
{
if (self = [super init])
{
//Switch direction based on slideDirection konstant
switch (dir) {
case kSlideUp: //slideup
// Notice the view y coordinate is offscreen (480)
// This hides the view
// What should I be doing here if I want to get the nib file???
self.frame = CGRectMake(0,480,320, 90);
[self setBackgroundColor:[UIColor blackColor]];
[self setAlpha:.87];
newY = 380;
newX = 0;
myDir = 0;
break;
default:
break;
}
}
return self;
}
#pragma mark -
#pragma mark Message Handling
- (void)showMsgWithDelay:(int)delay
{
// UIView *view = self.view;
CGRect frame = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.75];
// Slide up based on y axis
// A better solution over a hard-coded value would be to
// determine the size of the title and msg labels and
// set this value accordingly
frame.origin.y = newY;
frame.origin.x = newX;
self.frame = frame;
[UIView commitAnimations];
// Hide the view after the requested delay
[self performSelector:#selector(hideMsg) withObject:nil afterDelay:delay];
}
#pragma mark -
#pragma mark Cleanup
- (void)dealloc
{
if ([self superview])
[self removeFromSuperview];
[super dealloc];
}
#end
What do you mean with a "slide-up controller"? Just a view that slides up from the bottom? If so, you can just create a UIView with the buttons in it, and animate it. For the animation you can use UIView beginAnimations:context: and commitAnimations.