iAd works fine itself. When i click on iAd it loads a full screen ad. Then when i click out of iAd. and click on my start game button, the UIImageView in the game moves by itself in the direction depending on which side of the ad I clicked on. Don't know why touching the iAd affects UIImageView. I use a touchesBegan method to move UIImageView. What can I do to stop this iAd touch affect on UIImageView?
Used the following in VC.m to integrate iAd.
#pragma mark iAd Delegate Methods
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[banner setAlpha:0];
[UIView commitAnimations];
}
EDIT:
My touchesBegan method:
MoveLeft, moveRight, StopSideMove are all BOOL values in ViewController.h
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
moveLeft=NO;
moveRight=NO;
stopsideMove=YES;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
CGPoint point=[touch locationInView:self.view];
if (point.x <170) {
moveLeft=YES;
}
else
moveRight=YES;
}
Related
I am trying to get my image to fade out and fade in with when i click on my button. Is there something wrong with this code? My image stays visible when I click on my button.
- (IBAction)Alpha:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2];
_image.alpha = 1;
[UIView commitAnimations];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
}
-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
_image.alpha = 0;
[UIView commitAnimations];
}
You are calling the methods on UIVIew, the class, not on your instance of the UIImageView that you want to fade.
You'll want something like
[self.myImageView beginAnimations....
in my viewcontroller entered all the objects in a scrollview. One of the buttons inside the scrollView creates an animation.
The scrollView get off the page -80.0 orgine.y
So far so good .. Now I want that when you click on the button the scrollview and then goes back down to -80.0 to +80.0 automatically returning to its original position so ... Can you tell me the best method for you to have this?
This is the action that fulfills my button when pushed ...
- (IBAction)AcceptFriendRequest:(id)sender {
PFObject *SelectedUser = [self.UtentiInAttesa objectAtIndex:[sender tag]];
[SelectedUser setObject:#"Confermato" forKey:#"STATO"];
[SelectedUser saveInBackground];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.2];
[UIView setAnimationBeginsFromCurrentState:YES];
FFScrollView.frame = CGRectMake(FFScrollView.frame.origin.x, (FFScrollView.frame.origin.y - 80.0), FFScrollView.frame.size.width, FFScrollView.frame.size.height);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView commitAnimations];
}
In your button event handler
- (IBAction)myBtnClicked:(id)sender {
// Create new CGRect indicate place where you would scroll to.
// Assume it is called `originalRect`
// Use the following method, it should work
[FFScrollView.scroll scrollRectToVisible:originalRect animated:YES];
}
a view in my app roughly looks like this:
An UIImage, and beyond this, a TextView describing the image. - The text should be editable.
And now this is my question: When the user taps into the textfield, the appearend keyboard "lies over the text" (the user can't see, what he is writing).
Is there an easy to implement possibility (I'm a newbie to XCode) to swith the text to the upper part of the page, while editing it (something like: "if keyboard appers replace image by text", "if keyboard dissapears undo"),
such that the user can see the changes?
Thanks for your help,
Max
Firstly conform u are using Text Field or Text View, i m considering that u are using text Field
// #define kOFFSET_FOR_KEYBOARD 110.0 define this in the .m file and set its value accordingly
-(void)textFieldDidBeginEditing:(UITextField *)textField{
if(self.view.frame.origin.y >= 0)
[self setViewMoveUp:YES];
}
}
-(void)setViewMoveUp:(BOOL)moveUp{
CGRect rect = self.view.frame;
if(moveUp)
{
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else
{
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
}
do like this.When the delegate method called (i.e in did beginEditing method)
Write this code
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
[self.view setFrame:CGRectMake(0,-20,320,400)];
[UIView commitAnimations];
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
txtField.frame = CGRectMake(txtField.frame.origin.x, (txtField.frame.origin.y), txtField.frame.size.width,txtField.frame.size.height);
[UIView commitAnimations];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
UIInterfaceOrientation des=self.interfaceOrientation;
if (des==UIInterfaceOrientationLandscapeLeft||des==UIInterfaceOrientationLandscapeRight)
{
txtField.frame=CGRectMake(500,250,97,37);
}
[UIView commitAnimations];
}
}
" Don't forget to given this in Vied DidLoad"
self.view.frame=[[UIScreen mainScreen]applicationFrame];
view.autoresizesSubviews=NO;
txtField.delegate=self;
I would like to rotate an UIImageView clockwise around his center after pressing a button (360 degrees)... It should be an animation... So its getting a steering wheel, and it should rotate by itself visible for the user...
I saw there are many ways to do that, but nothing worked for me... :-)
The CABasicAnimation, do I have to add a framework for this?
Could someone give me a sample code, for rotating an UIImageView around its center for (360 degrees) that works?!?
thank you in advance
Hear given below i do same thing ...... but my requirement is when touchBegin that View will be rotate 360 degree ... it may help to you.....
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
self.userInteractionEnabled=YES;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self cache:YES];
[UIView commitAnimations];
[delegate changeImage:self];
}
-(void)changeImage:(DraggableImages *)selectedView
{
count++;
clickCounter++;
counterLable.text=[NSString stringWithFormat:#"%i",clickCounter];
selectedView.image=[images objectAtIndex:selectedView.tag];
if (count==1) {
firstSelectedView=selectedView;
}
if (count==2) {
self.view.userInteractionEnabled=NO;
secondSelectedView=selectedView;
count=0;
[self performSelector:#selector(compareImages) withObject:nil afterDelay:0.7];
}
}
-(void)compareImages
{
if (firstSelectedView.tag==secondSelectedView.tag)
{
matches++;
//NSLog(#"%#",matches);
Score=Score+10;
scoreLable.text=[NSString stringWithFormat:#"%d",Score];
firstSelectedView.alpha=0.5;
secondSelectedView.alpha=0.5;
self.view.userInteractionEnabled=YES;
if(matches==[images count])
{
[timer invalidate];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:#"Do you want to countinue?"] delegate:self cancelButtonTitle:nil otherButtonTitles:#"YES",#"NO", nil];
[alertView show];
[alertView release];
}
}
else {
Score=Score-1;
scoreLable.text=[NSString stringWithFormat:#"%d",Score];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:firstSelectedView cache:YES];
firstSelectedView.image=[UIImage imageNamed:#"box.jpg"];
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:secondSelectedView cache:YES];
secondSelectedView.image=[UIImage imageNamed:#"box.jpg"];
[UIView commitAnimations];
firstSelectedView.userInteractionEnabled=YES;
secondSelectedView.userInteractionEnabled=YES;
self.view.userInteractionEnabled=YES;
}
}
You need to add the QuartzCore framework, and you can read more about CABasicAnimation.
Some Tutorials
Interrupting Animation Progress
Slider Based Layer Rotation
CABasicAnimation basics
Core Animation Paths
Upon button press invoke this method:
- (void) animate{
CABasicAnimation *imageRotation = [CABasicAnimation animationWithKeyPath:#"transform.rotation"];
imageRotation.removedOnCompletion = NO; // Do not turn back after anim. is finished
imageRotation.fillMode = kCAFillModeForwards;
imageRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
imageRotation.duration = 1.5;
imageRotation.repeatCount = 1;
[yourImageView.layer setValue:imageRotation.toValue forKey:imageRotation.keyPath];
[yourImageView.layer addAnimation:imageRotation forKey:#"imageRotation"];
}
and yes as WrightsCS has stated, you will need QuartzCore framework included in your project. Dont forget the import statement:
#import <QuartzCore/QuartzCore.h>
How can I make sure that the images that are within my scroller will be able to be dragged from the scroller to the imageview?
I also would like to implement a 'wiggle'. When a user taps an image within the scroller the images wiggles and follows the touch of the user to the other view. I started with making a subview, however when the image displays itself on the normal view its location changes to be on top of the view instead of on the bottom.
How can I make sure that when I touch an image:
the image wiggles
the images go to another view.
the images follow my touch position
(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
image1.userInteractionEnabled = YES;
[self.view addSubview:image1];
if([touch view] == image1){
image1.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.14];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000000];
image1.transform = CGAffineTransformMakeRotation(69);
image1.transform = CGAffineTransformMakeRotation(-69);
[UIView commitAnimations];
image1.center = CGPointMake(30,870);
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *) event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if([touch view] == image1){
image1.userInteractionEnabled = YES;
[self.view addSubview:image1];
image1.center = location;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.14];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000000];
image1.transform = CGAffineTransformMakeRotation(69);
image1.transform = CGAffineTransformMakeRotation(-69);
[UIView commitAnimations];
}
In stead of using the 'touches functions' I used gestureRecognizers. You can put a recognizer on a certain image (TapRecognizer of LongpressRecognizer). When a user presses the image the App recognizes the touch. Afterwords you can put the image in a subview on top of your normal view with the function "[self.view addSubview:yourImage];"
Here's a snippit
First you declare the gesturerecognizer in your viewDidLoad, viewDidAppear or viewWillappear method
UILongPressGestureRecognizer *longPress =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longPressed:)];
longPress.minimumPressDuration = 0.7;
[yourimage addGestureRecognizer:longPress1];
Afterwords you use the delegate function
-(void)longPressed:(UILongPressGestureRecognizer *)sender {
CGPoint location = [sender locationInView:self.view];
[self.view addSubview:yourimage];
yourimage.center = location;
//perform a transform (wiggle or scale)
if([(UILongPressGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
yourimage.transform = CGAffineTransformMakeScale(1.0, 1.0);
//stop the transform
}
}
Hope this helps you out Elppa