Can anyone say how to implement transition segue like in facebook app when i open image to fullscreen?
I fount this example http://joris.kluivers.nl/blog/2013/01/15/custom-view-controller-transitions-using-uistoryboardsegues/
but it blinking during the transition on ios7 and i don't understand how to fix it( Have anyone any ideas?
The blinking is being caused by the temporary image that is created to simulate the transition being removed before the image is unhidden in the new view. I changed the completion block to delay by .25 seconds to allow for the image to be unhidden.
[UIView animateWithDuration:0.4f delay:.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
imageView.frame = dest;
if (self.unwinding) {
[self.destinationViewController dismissViewControllerAnimated:YES completion:nil];
} else {
((UIViewController *)self.destinationViewController).modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.sourceViewController presentViewController:self.destinationViewController animated:YES completion:nil];
}
} completion:^(BOOL completed) {
int64_t delayInSeconds = 1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC/4);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
imageView.hidden = YES;
[imageView removeFromSuperview];
});
}];
Related
I have a little iOS5 app that shows images. I click on the image to show its information. I'd like the information to fade away after a few seconds. Is there a good method to do this?
I can always implement another button action but this would be neater..
Thanks!
Use either NSTimer or performSelector:withObject:afterDelay. Both methods require you to call a separate method that will actually do the fading out which should be fairly straightforward.
Example:
NSTimer
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(fadeOutLabels:) userInfo:nil repeats:NO];
performSelector:withObject:afterDelay:
/* starts the animation after 3 seconds */
[self performSelector:#selector(fadeOutLabels) withObject:nil afterDelay:3.0f];
And you will call the method fadeOutLabels (or whatever you want to call it)
-(void)fadeOutLabels
{
[UIView animateWithDuration:1.0
delay:0.0 /* do not add a delay because we will use performSelector. */
options:UIViewAnimationCurveEaseInOut
animations:^ {
myLabel1.alpha = 0.0;
myLabel2.alpha = 0.0;
}
completion:^(BOOL finished) {
[myLabel1 removeFromSuperview];
[myLabel2 removeFromSuperview];
}];
}
Or you can use the animation block to do all of the work:
-(void)fadeOutLabels
{
[UIView animateWithDuration:1.0
delay:3.0 /* starts the animation after 3 seconds */
options:UIViewAnimationCurveEaseInOut
animations:^ {
myLabel1.alpha = 0.0;
myLabel2.alpha = 0.0;
}
completion:^(BOOL finished) {
[myLabel1 removeFromSuperview];
[myLabel2 removeFromSuperview];
}];
}
I'm trying to add an effect to a switch between 2 views. The switch happen just rotating the device. So far I'm able to apply the effect when from portrait go to landscape, but not viceversa.
Here's my code:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait)
{
/* If I run with this block, I have a Exc Bad Access Error and can't run, so I put it
under comment
[UIView transitionWithView:self.view duration:1.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.portraitView];
} completion:NULL];
*/
self.view = self.portraitView;
//[self dismissModalViewControllerAnimated:YES];
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==
UIInterfaceOrientationLandscapeRight)
{
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.landscapeView];
} completion:NULL];
[self dismissModalViewControllerAnimated:NO];
}
}
In this way I have the desired effect when passing from Portrait to Landscape, but when I put the device back to Portrait it doesn't load the portraitView, the landscapeView remains on.
Hope somebody can help me.
EDIT:
I just edited my above code in this way:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationPortrait)
{
if (self.isViewLoaded && self.view.window)
{
NSLog(#"Portrait1");
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
NSLog(#"Portrait2");
[self.view.window addSubview:self.portraitView];
} completion:NULL];
[self dismissModalViewControllerAnimated:YES];
}
}
else if (deviceOrientation == UIDeviceOrientationLandscapeLeft || deviceOrientation ==
UIDeviceOrientationLandscapeRight)
{
[UIView transitionWithView:self.view duration:1
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.view addSubview:self.landscapeView];
} completion:NULL];
[self dismissModalViewControllerAnimated:NO];
NSLog(#"Landscape");
}
}
And the effect works fine. But I have the big issue that when I switch back from Landscape to Portrait the landscapeView remains ON the portraitView. How could I dismiss it?
Referring to your updated code, when your device orientation becomes UIDeviceOrientationPortrait, you are making the mistake of adding portraitView as a subview to self.view.window instead of self.view.
Also, what is the purpose behind [self dismissModalViewControllerAnimated:NO]? You haven't actually presented a modal view controller anywhere, so it doesn't serve any purpose.
I have a device connected to my iPad that is acting as an external keyboard, however, I still need a soft keyboard in my program. I have had some luck using the following article: Show iphone soft keyboard even thought a hardware keyboard is connected, but iOS 5 has broken this method. The bottom of the soft keyboard is slightly cut off in most views, but others only half the keyboard appears inside the window and not where you would expect it to.
All of the following code works in my AppDelegate.m file in iOS4, but not in iOS5.
forceKeyboard is called after UITextFieldTextDidBeginEditingNotification is sent.
-(void) textFieldBegan: (NSNotification *) theNotification
{
UITextField *theTextField = [theNotification object];
theTextField.inputAccessoryView = inputAccessoryView;
[self performSelector:#selector(forceKeyboard) withObject:nil afterDelay:0];
}
//Change the inputAccessoryView frame
-(void) forceKeyboard
{
inputAccessoryView.superview.frame = CGRectMake(0, 502, 1024, 265);
int movementDistance = 1;
float movementDuration = 0.3f;
[UIView beginAnimations: #"kb_anim_open" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
inputAccessoryView.superview.frame = CGRectOffset(inputAccessoryView.superview.frame, 0, movementDistance);
[UIView commitAnimations];
}
Close Keyboard is called after UITextFieldTextDidEndEditingNotification is sent.
-(void) textFieldEnd: (NSNotification *) theNotification
{
UITextView *theTextView = [theNotification object];
[theTextView resignFirstResponder];
[self performSelector:#selector(forceCloseKeyboard) withObject:nil afterDelay:0];
}
-(void) forceCloseKeyboard
{
inputAccessoryView.superview.frame = CGRectMake(0, 502, 1024, 265);
int movementDistance = 502;
float movementDuration = 0.3f;
[UIView beginAnimations: #"kb_anim_close" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
inputAccessoryView.superview.frame = CGRectOffset(inputAccessoryView.superview.frame, 0, movementDistance);
[UIView commitAnimations];
}
Any ideas on how I can tame a soft keyboard would be greatly appreciated; I've tried wrestling with the superview.frame values for awhile but with no luck.
Thanks for reading.
UPDATE
I have figured out a setup that opens and closes the keyboard in iOS 4 and 5, but does not animate. Again, this is all in the AppDelegate where "textFieldBegan" and "textFieldEnd" are called by notifications sent when a user begins and ends editing respectively.
-(void) textFieldBegan: (NSNotification *) theNotification
{
UITextField *theTextField = [theNotification object];
if (!inputAccessoryView) {
inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 1)];
}else{
inputAccessoryView.frame = CGRectMake(0, 0, 1024, 1);
}
theTextField.inputAccessoryView = inputAccessoryView;
[self performSelector:#selector(forceKeyboard) withObject:nil afterDelay:0];
}
-(void) textFieldEnd: (NSNotification *) theNotification
{
NSString *classstr = NSStringFromClass([[theNotification object] class]);
UITextView *theTextView = [theNotification object];
[self performSelector:#selector(forceCloseKeyboard) withObject:nil afterDelay:0];
[theTextView resignFirstResponder];
}
//Change the inputAccessoryView frame
-(void) forceKeyboard
{
//default center = 512, 591
inputAccessoryView.superview.frame = CGRectMake(0, 415, 1024, 353);
[UIView animateWithDuration:0.3 animations: ^ { [inputAccessoryView.superview transform]; }];
}
-(void) forceCloseKeyboard //Unnecessary?
{
inputAccessoryView.frame = CGRectMake(0, 0, 1024, 0);
[UIView animateWithDuration:0.3 animations: ^ { [inputAccessoryView transform]; }];
}
It looks as if the "forceCloseKeyboard" method isn't really doing anything as it looks like when the textField resigns responder it closes the keyboard anyway. I leave it here in case someone can come up with a way to animate the keyboard opening and closing.
I'm having a little problem. I have an UILabel which have an UILongPressGestureRecognicer. When the UILongPressGestureRecognizer is called my app is supposed to switch to a new view using a flip animation.
This is the code I have used for the GestureRecognizer:
UILongPressGestureRecognizer *labelLongPressRecognizer;
labelLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(LoadLabelSettings:)];
labelLongPressRecognizer.numberOfTouchesRequired = 1;
labelLongPressRecognizer.minimumPressDuration = 2.0;
[NewLabel addGestureRecognizer:labelLongPressRecognizer];
and this is the code for the view switching animation:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.view addSubview:LabelSettingsViewController.view];
[UIView commitAnimations];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
LabelSettingsViewController.view.frame = CGRectMake(0, 0, 480, 300);
}
My problem is that when I hold down on my UILabel the switch animation begins, but when I release it repeats the animation again. So basically the animation occur twice and I only want it to take place once.
Any ideas?
Thanks in advance :)
Are you checking the sender state, e.g.,
- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded) // or whatever
// then do the flipping stuff
}
Check out the "Overview" of the "UILongPressGestureRecognizer Class Reference", which talks about the long press being continuous and I presume numerous events could be triggered:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html
is it possible to create a design something like this?
any help regarding this would be very helpful for me.the functionality i want is to rotate the wheel left-to-right or right to left for selecting time...yellow is selection color and red is shows the remaining time when countdown is running
Use a Gallery view object. Just fill it with the images you want to scroll horizontally.
This would be a good approximation to what you're looking to achieve.
See my video
http://www.youtube.com/watch?v=4acFshAlGJ8
I have use
https://lh3.googleusercontent.com/-WZEDMSmfrK0/TeeD93t8qYI/AAAAAAAAAKw/X9D6jRkLfLk/s800/MUKScale.png
image as Scale in the scrollView this is an incomplete example just to show how can it is achievable.
here is some helpful piece of code,
in this approx everything is static but for the real work one should to work more,
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:scrollView];
UIImageView *backImgg = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,886,15)];
[backImgg setImage: [UIImage imageNamed:#"MUKScale.png"]];//Image in the link above
[scrollView addSubview:backImgg];
[backImgg release];
[scrollView setContentSize:CGSizeMake(886,15)];
return;
}
NSTimer *timer ;
float timeSet =0 ;
-(IBAction) btnPressed
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(showTimeInLbl) userInfo:nil repeats:YES];
}
-(void)showTimeInLbl
{
CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.contentSize;
NSLog( #"Visible rect: %#", NSStringFromCGRect(visibleRect) );
float time = visibleRect.origin.x / 8;
timeSet = time;
lblTime.text = [NSString stringWithFormat:#"%f",time];
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(visibleRect.origin.x - 8,0) animated:NO];
}completion: ^(BOOL finished){
}
];
timeSet-=0.1;
lblTime.text = [NSString stringWithFormat:#"%f",timeSet];
if(timeSet<=0)
{
[timer invalidate];
lblTime.text = #"0";
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){
}
];
}
}
You can use a Never Ended scrollView (For example this you have in it like off paging).
Now by this you will achieve the scale and by using page no or coordinates of the scrollview you can find the scale reading to show on above.
On start count down create animation of UIView contentOffset CGPointMake(10, 100).
for example:
[UIView animateWithDuration: 1.5 /* Give Duration which was also on top */
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){ }];