I am creating an ePub reader, which reads ePub files. I want to implement a page slide effect similar to a physical book. For example.
What animation is this? This doesn't work:
- (void)loadPage{
[UIView beginAnimations:nil context:nil];
//change to set the time
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
// do your view swapping here
[UIView commitAnimations];
}
on swipe:
- (void)swipeRightAction:(id)ignored
{
NSLog(#"Swipe Right");
if (_pageNumber>0) {
_pageNumber--;
[self loadPage];
}
}
- (void)swipeLeftAction:(id)ignored
{
NSLog(#"Swipe Left");
if ([self._ePubContent._spine count]-1>_pageNumber) {
_pageNumber++;
[self loadPage];
}
}
I have done the same with third party api. You can take refrence from below URL
https://github.com/jemmons/PageCurl
https://github.com/xissburg/XBPageCurl
https://github.com/brow/leaves
Related
Update, SOLVED
Sorry for my english, but i will do my best.
I have a problem with a button flip animation.
I want the UIButtons to fill the UIView. But how do i do that?
Here is my problem.
I have two UIButtons in a UIView.
When i press the first button it will flip correctly but when i press the second button that it have flipped to the UIView is still the same size but the UIButton image is changing size to the original size of the image and it also move the image to the upper left corner off the view controller. The same thing will repeat every time it flip.
Here is the flip animation code.
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.btn1 removeFromSuperview];
[buttonContainer addSubview:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.btn2 removeFromSuperview];
[buttonContainer addSubview:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
Have a nice day and thanks for any help!
I solved the problem like this
- (IBAction) buttonPressedFlip {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
if (flipState == 0) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn2];
flipState = 1;
}
else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonContainer cache:YES];
[self.buttonContainer bringSubviewToFront:btn1];
flipState = 0;
}
[UIView commitAnimations];
}
I solved the problem
See my update code.
I have set up iAds for my app, but for whatever reason, they only appear on the iphone 4 inch and not the 3.5 inch. First, I thought it had something to do with the Auto Layout, so I made sure the BannerView appeared in both screen sizes. After doing so, I ran and still would not work.
Here is the code I used to tell the bannerView what to do. This is in the ViewController.m file.
#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];
}
Also, this is being done in Spritekit if that matters.
Thanks for helping, and I'm pretty new to coding so something that may seem obvious, I might have easily not noticed.
You cannot animate the alpha of an object. Alternatively, you should be modifying it's transparency via it's opacity:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 1.0f;
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[UIView animateWithDuration:1.0 animations:^{
banner.layer.opacity = 0.0f;
}];
}
So, I am trying to implement iAds into my application, but I cannot get it to work properly.
I am using these two functions to show and hide the banner and it works great:
- (void)showAdBanner:(ADBannerView *)banner {
if (bannerVisible) return;
NSLog(#"showing ad");
[UIView beginAnimations:#"animateBannerIn" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[banner setFrame:CGRectOffset([banner frame], 0, -bannerHeight)];
[toolbarView setFrame:CGRectOffset([toolbarView frame], 0, -bannerHeight)];
[UIView commitAnimations];
bannerVisible = YES;
}
- (void)hideAdBanner:(ADBannerView *)banner {
if (!bannerVisible) return;
NSLog(#"hiding ad");
[UIView beginAnimations:#"animateBannerOut" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[banner setFrame:CGRectOffset([banner frame], 0, bannerHeight)];
[toolbarView setFrame:CGRectOffset([toolbarView frame], 0, bannerHeight)];
[UIView commitAnimations];
bannerVisible = NO;
}
The only issue is that after one presses on the iAd banner, the toolbar view returns to its original position sans-iAd.
I have removed all layout constraints and it still is occurring. I can attach a video after if it clarifies.
Thank you
Video: https://www.dropbox.com/s/64mbiowk94sl6rq/iAdIssue.mov
I am use this code when a cell is tapped in an uitableview that exists inside an uiview but is not doing the "flash" that is supposed to do on the cell when the user taps it.
-(IBAction)labelTap:(UIGestureRecognizer *)sender
{
if(sender.state != UIGestureRecognizerStateRecognized)
return;
UIView *tappedview=[sender.view hitTest:[sender locationInView:sender.view]
withEvent:nil];
UIView *contentview1=tappedview.superview.superview;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[contentview1 setAlpha:0];
[contentview1 setAlpha:1];
[UIView commitAnimations];
}
Any help appreciated.
Try this is working!
UIView *contentview1=tappedview.superview;
[contentview1 setAlpha:0];
[UIView animateWithDuration:0.3f
animations:^(void)
{
// Animate the flash on tap
[contentview1 setAlpha:1];
}
completion:^(BOOL finished)
{
NSLog(#"Done! Now show the pop up");
)];
I've been trying to fade in an MKMapView when we have successfully found the address, and fade out the view when long & lat == 0. I have the code in the delegate:
- (void)didCompleteMapsRequestWithLatitude:(double)latitude andLongitude:(double)longitude
Simple actions work as expected (e.g., setHidden:YES or setHidden:NO) at the correct time.
My problem is that while the fade in seems to work well every time it's called, the fade out animation doesn't appear to happen. It's as if the only call is setHidden:YES.
My fade code is as follows:
//no location found
if (location.latitude == 0 && location.longitude == 0)
{
//fade out
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[self.map setAlpha:0.0];
[UIView commitAnimations];
[self.map setHidden:YES];
}
//we found the location on the map
else
{
[self.map setHidden:NO];
//fade in
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[self.map setAlpha:1.0];
[UIView commitAnimations];
}
Note I get the same behaviour using animation blocks with iOS 4.0.
Any thoughts?
Thanks
I think you need to run [self.map setHidden:YES] when the animation completed, like this:
[UIView animateWithDuration:1.0
animations:^{
self.map.alpha=0.0;
}
completion:^(BOOL finished){
self.map.hidden=YES;
}];