Marquee effect in uiimageview iPhone - iphone

How can I implement marquee effect animation in UIImage.
I have a image of cloud (320*480). I need to animation it continuously left from right without any lagging and disappearing. Below is a sample of html.
http://www.quackit.com/html/codes/html_marquee_code.cfm
2nd from top(Continuous scrolling text:).
Please help

UIImage *clouds = [UIImage imageNamed:#"Clouds"];
UIImageView *cloudView = [[UIImageView alloc] initWithImage:clouds];
CGRect origin = CGRectMake(320, 0, clouds.size.width, clouds.size.height);
CGRect destination = CGRectMake(0, 0, clouds.size.width, clouds.size.height);
cloudView.frame = origin;
[self.view addSubview:cloudView];
[UIView animateWithDuration:5 delay:0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear animations:^{
cloudView.frame = destination;
} completion:nil];

Do this:
-(void)marqueeEffect
{
imgView.frame = CGRectMake(self.view.frame.origin.y,50,320,480); //right frame
//increase time duration as per requirement
[UIView animateWithDuration:3.0
delay: 0.0
options: UIViewAnimationCurveEaseOut
animations:^{
imgView.frame = CGRectMake(-imgview.frame.size.width,50,320,480); //left frame
}
completion:^(BOOL finished){
[self performSelector:#selector(marqueeEffect)];
}];
}

TRY THIS EXAMPLE , ITS FOR UILABEL:
int x;
#synthesize label;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
label=[[UILabel alloc]initWithFrame:CGRectMake(300, 400, 150, 30)];
label.text=#"WWW.SONGS.PK";
label.backgroundColor=[UIColor clearColor];
x=300;
[NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:#selector(clickme) userInfo:nil repeats:YES];
}
-(void)clickme
{
x--;
label.frame=CGRectMake(x, 400, 150, 30);
if( x==-150)
{
x=300;
}
[self.view addSubview:label];
}

Related

Drawing Line in Two Views At a Time

I am doing an app in which i need to draw lines in one view and that automatically should appear in the other view. Any help would be appreciated..
I have tried this..
- (void)viewDidLoad
{
[super viewDidLoad];
slv = [[SmoothLineView alloc] initWithFrame:CGRectMake(DrawingView.bounds.origin.x, DrawingView.bounds.origin.y + 42, DrawingView.bounds.size.width, DrawingView.bounds.size.height - 42)];
slv.delegate = self;
[DrawingView addSubview:slv];
}
-(IBAction)btnAnotherView:(UIButton *)sender
{
[zoomingTypingView setUserInteractionEnabled:YES];
if(sender.tag == 123)
{
[self.view setBackgroundColor:[UIColor colorWithWhite:0.500 alpha:1.000]];
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationTransitionCurlUp
animations:^{
//animation code
zoomingTypingView.frame = CGRectMake(0, 549, 768, 451);
} completion:^(BOOL finished) {
}];
CGRect imageFrame = CGRectMake(50, 50, 220, 120);
ResizableView = [[SPUserResizableView alloc] initWithFrame:imageFrame];
CGRect gripFrame = CGRectMake(50,50, 220,120);
UIView *zoom = [[UIView alloc]initWithFrame:gripFrame];
UIScrollView *zoomscroll = [[UIScrollView alloc]initWithFrame:gripFrame];
[zoomscroll setZoomScale:32.0];
[zoomscroll setMaximumZoomScale:32.0];
[zoom addSubview:zoomscroll];
[ResizableView setContentView:zoom];
ResizableView.delegate = self;
[DrawingView addSubview:ResizableView];
sender.tag = 246;
}
else
{
[UIView animateWithDuration:0.5
delay:0.1
options:UIViewAnimationTransitionCurlUp
animations:^{
//animation code
zoomingTypingView.frame = CGRectMake(0, 999, 768, 451);
} completion:^(BOOL finished) {
[self.view setBackgroundColor:[UIColor whiteColor]];
}];
[ResizableView removeFromSuperview];
[DrawingView addSubview:slv1];
sender.tag = 123;
}
}
In the above Image WhiteColored View is the new View and if i draw in that whiteColoredView that should reflect in both the views.
You can get more idea by looking at the NOTE TAKER HD APP.
http://www.youtube.com/watch?v=FdGDnUKZcMM
If you have two views defined:
#property(nonatomic) UIView *view1;
#property(nonatomic) UIView *view2;
instead of do self.view, you can have function does the drawing for one view:
-(void)drawView:(UIView*)view{
//your drawing code here
}
And just call the same function twice with passing different views.

status message corrupts main window in my iPhone app

In my iOS app when a button is pressed an event is initiated and at the bottom of the screen appears a status message informing the user about a successful or failed operation.
The status message appear and disappear with the following code.
this one show the message
- (void) showMessage:(NSString*)text
{
CGRect frame = [[self view] frame];
if(statusView == nil)
{
messageViewWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, frame.size.height-29,
frame.size.width, 0)];
statusView = [[StatusMessageView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 0)
Text:text
andShowIndicator:NO];
[messageViewWindow addSubview:statusView];
[messageViewWindow makeKeyAndVisible];
}
UILabel *label = [statusView getTextLabel];
UIImageView *imageView = [statusView getBackImageView];
CGSize stringSize = [text sizeWithFont:[Constants getLabelFont]];
int xCoordinate = (messageViewWindow.frame.size.width - stringSize.width)/2;
[UIView beginAnimations:nil context:nil];
messageViewWindow.frame = CGRectMake(0, frame.size.height-59, frame.size.width, 30);
statusView.frame = CGRectMake(0, 0, frame.size.width, 30);
label.frame = CGRectMake(xCoordinate,5,stringSize.width,20);
imageView.frame = CGRectMake(0, 0, frame.size.width, 30);
[UIView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:#selector(hideMessage) userInfo:nil repeats:NO];
}
and this one hides the message
- (void) hideMessage
{
UILabel *label = [statusView getTextLabel];
UIImageView *imageView = [statusView getBackImageView];
CGRect labelFrame = label.frame;
[UIView beginAnimations:nil context:nil];
messageViewWindow.frame = CGRectMake(0, [UIScreen mainScreen].applicationFrame.size.height-29, [UIScreen mainScreen].applicationFrame.size.width, 0);
statusView.frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0);
label.frame = CGRectMake(labelFrame.origin.x, 0, labelFrame.origin.y, 0);
imageView.frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, 0);
[UIView commitAnimations];
}
strange thing is that the message is shown and after two seconds dissapears, however the main window lost functionality, like the copy and paste ability.
Do you see something wrong in my methods? Is there any certain way, calling the "animations" code?
Since you are writing [messageViewWindow makeKeyAndVisible];, you have to write [self.view.window makeKeyAndVisible] in hideMessage to let the self.view.window handle all the userinteraction again.
This is because you use a UIWindow to display your view, which is not a good idea (it is not recommended to create UIWindows by yourself, as explained in the "Overview" paragraph of the documentation.
Moreover, you make your window the keywindow but don't restore the standard window at the end when you hide it, thus your problems with the events later.
And last, you use obsolete APIs for the animations, which is deprecated since iOS4 is out (and I guess you don't code for iOS3 or earlier), you should really use the new APIs that have been introducted 3 iOS versions ago now. Besides, it will avoid the overhead to create an NSTimer for that.
So you code can become:
- (void) showMessage:(NSString*)text
{
CGSize sz = self.view.window.frame.size;
CGRect hiddenFrame = CGRectMake(0, sz.height-29, sz.width, 0);
if(statusView == nil)
{
statusView = [[StatusMessageView alloc] initWithFrame:hiddenFrame
text:text
andShowIndicator:NO];
[self.window addSubview:statusView];
}
UILabel *label = [statusView getTextLabel];
UIImageView *imageView = [statusView getBackImageView];
CGSize stringSize = [text sizeWithFont:[Constants getLabelFont]];
int xCoordinate = (sz.width - stringSize.width)/2;
label.frame = CGRectMake(xCoordinate,5,stringSize.width,20);
imageView.frame = CGRectMake(0, 0, frame.size.width, 30);
[UIView animateWithDuration:1.f animations:^{
statusView.frame = CGRectMake(0, sz.height-59, frame.size.width, 30);
} completion:^{
// When show animation is done, schedule the start of the hide animation with a delay of 2 seconds
[UIView animateWithDuration:1.f delay:2.f options:0 animation:^{
statusView.frame = hiddenFrame;
} completion:nil];
}];
}

How to animate expand and shrink uiview in place?

I have a series of uiviews, and i want to create an animation where a button press event will expand the uiview from the bottom and reveal more information about the view. Another button press will shrink the view back to original.
How do i proceed with this?
There are a series of uiviews laid out in a horizontal scroll view like a coverflow. I want to display additional information about each uiview on click of a button.
Do drop a comment if you need more information.
TIA,
Praveen S
This code will expand your view...do the reverse to shrink it
CGRect tempFrame=view.frame;
tempFrame.size.width=200;//change acco. how much you want to expand
tempFrame.size.height=200;
[UIView beginAnimations:#"" context:nil];
[UIView setAnimationDuration:0.2];
view.frame=tempFrame;
[UIView commitAnimations];
For that use this code
In .h file
#import <UIKit/UIKit.h>
#interface ExpandedViewController : UIViewController
{
UIView * expandiView;
BOOL viewExpanded;
}
- (IBAction)expandOrShrinkView:(id)sender;
#end
and in your .m file
- (void)viewDidLoad
{
[super viewDidLoad];
aview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
aview.backgroundColor = [UIColor redColor];
[self.view addSubview:aview];
viewExpanded = NO;
}
And in your button action add this code
- (IBAction)expandOrShrinkView:(id)sender {
[UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionTransitionNone animations: ^{
if (!viewExpanded) {
viewExpanded = YES;
aview.frame = CGRectMake(10, 10, 100, 200);
}else{
viewExpanded = NO;
aview.frame = CGRectMake(10, 10, 100, 100);
}
} completion:nil];
}
When you click the button first time it will expand the view from bottom and when you click the button second time it will shrink the View from bottom change the frame size to your need..
And if you want shrink function in another button than use two action method like this
- (IBAction)expandView:(id)sender {
[UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionTransitionNone animations: ^{
aview.frame = CGRectMake(10, 10, 100, 200);
} completion:nil];
}
- (IBAction)ShrinkView:(id)sender {
[UIView animateWithDuration:0.8f delay:0.0f options:UIViewAnimationOptionTransitionNone animations: ^{
aview.frame = CGRectMake(10, 10, 100, 100);
} completion:nil];
}

How to specify a size to a UIAlert

I am trying to display a UIImage in a UIAlert.
I want to display it nearly fullscreen. For example my image has a 300x450px size.
Well I add it as a subview to my UIAlert.
But the UIAlert has default coordinates to keep it centered.
So I can add a image bigger than the UIAlert frame, but it covers the UIAlert...
I tried to specify a frame for my UIAlert, but it has no effect on it.
In fact I would like to add my image as a real content of the UIAlert, as well as simple text.
Is this possible ?
Consider writing your own Dialog popup instead of messing with the UIAlertView. If you want the 'bounce-in' animation that can easily be achieved using transform animations. Here is a simple popup dialog box I've just made.
To test it out create a new View-Based Application project and add this class. Then you can test it by adding the 'usage' code below to your *ViewController.m
This is a very simple example to demo the theory. It would make more sense to have a static method in SimpleDialog that shows the popup, but I didn't want to make the example overly complex.
SimpleDialog.h
#import <UIKit/UIKit.h>
#interface SimpleDialog : UIView
{
}
- (void) show;
#end
SimpleDialog.m
#import "SimpleDialog.h"
#define BOUNCE_SPEED 1
#implementation SimpleDialog
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code
self.backgroundColor = [UIColor greenColor];
UIButton* closeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
closeButton.frame = CGRectMake(0, 0, 200, 20);
closeButton.center = self.center;
[closeButton setTitle:#"Close" forState:UIControlStateNormal];
[closeButton addTarget:self action:#selector(hide) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:closeButton];
}
return self;
}
- (void) show
{
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
{
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}
[window addSubview:self];
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2*BOUNCE_SPEED];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounceInStopped)];
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
[UIView commitAnimations];
}
- (void)bounceInStopped
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.15*BOUNCE_SPEED];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounceOutStopped)];
self.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
[UIView commitAnimations];
}
- (void)bounceOutStopped
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.15*BOUNCE_SPEED];
self.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
- (void) hide
{
[self removeFromSuperview];
}
#end
Usage
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton* popButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
popButton.frame = CGRectMake(0, 0, 200, 20);
popButton.center = self.view.center;
[popButton setTitle:#"Pop" forState:UIControlStateNormal];
[popButton addTarget:self action:#selector(showIt) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:popButton];
}
- (void) showIt
{
SimpleDialog* simple = [[SimpleDialog alloc] initWithFrame:CGRectMake(0, 0, 300, 400)];
simple.center = self.view.center;
[self.view addSubview:simple];
[simple show];
[simple release];
}
Yes this is possible.
But it requires to customize the UIAlertView.
Using UIAlertView customization you can add anything.

transition animation on only a part of the screen

I am displaying two images in my iPhone app, one on top, one on the bottom. They cover the entire screen. The user, with a swipe gesture, can change either of the images, depending on where the swipe started.
I want the image to change with an animated transition. It currently works without animation, or with the entire screen transitioning. Is it possible to make the transition occur over part of the screen?
I load the images for the first time (in viewDidLoad) thus:
// top image
UIImage *topImage = [UIImage imageNamed:#"top1.png"];
CGRect topframe = CGRectMake(0.0f, 0.0f, 320.0f, 240.0f);
UIImageView *topView = [[UIImageView alloc] initWithFrame:topframe];
topView.image = topImage;
[self.view addSubview:topView];
[topView release];
// bottom image
UIImage *bottomImage = [UIImage imageNamed:#"bottom1.png"];
CGRect bottomframe = CGRectMake(0.0f, 240.0f, 320.0f, 240.0f);
UIImageView *bottomView = [[UIImageView alloc] initWithFrame:bottomframe];
bottomView.image = bottomImage;
[self.view addSubview:bottomView];
[bottomView release];
When I detect a swipe, and detect which of the two images are to be changed, I call a routine like this one:
- (void)changeTopImage:(NSString *)newImage {
UIImage *topImage = [UIImage imageNamed:newImage];
CGRect topframe = CGRectMake(0.0f, 0.0f, 320.0f, 240.0f);
UIImageView *topView = [[UIImageView alloc] initWithFrame:topframe];
topView.image = topImage;
[self.view addSubview:topView];
[topView release];
}
Essentilly, I'm continually loading images on top of each other. Is that the best way to do it, especially in terms of memory management?
Everything else I've tried, using techniques such as below, make the entire screen transition:
[UIView beginAnimations:nil context:nil];
...
[UIView commitAnimations];
Thanks for any leads on which way I should be going on this.
well, an easy way could be this (repeat for the bottomImage):
don't release topView when you load it the first time in your method,
but declare it in your .h file,
and use a tempView too:
#interface YourClass: UIViewController{
UIImageView *topView;
UIImageView *tempView;
}
this way you can call them to move them and remove them when you load a new image
then in .m:
EDIT: some correction (see coco's comments):
[a] [b] line 4 = [c] line 11:
- (void)changeTopImage:(NSString *)newImage {
UIImage *topImage = [UIImage imageNamed:newImage];
//CGRect topframe = CGRectMake(0.0f, 0.0f, (320.0f + 320), 240.0f);
CGRect topframe = CGRectMake((0.0f + 320), 0.0f, 320.0f, 240.0f);
tempView = [[UIImageView alloc] initWithFrame:topframe];
//topView.image = topImage;
tempView.image = topImage;
[self.view addSubview:tempView];
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView beginAnimations:#"animation" context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
tempView.center = topView.center;
// do this to push old topView away, comment next line if wanna new image just cover it
//topView.center = CGPointMake(topView.x - 320, topView.y);
topView.center = CGPointMake(topView.center.x - 320, topView.center.y);
// call a method when animation has finished:
[UIView setAnimationDidStopSelector:#selector(endOfAnimation:finished:context:)];
[UIView commitAnimations];
}
- (void)endOfAnimation:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
[topView removeFromSuperview];
topView = tempView;
[tempView release];
tempView = nil;
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}
- (void)dealloc {
if (tempView != nil) {
[tempView release];
}
[topView release];
[super dealloc];
}