Ha ii everybody,i am familiar with pullDownToRefresh in tableview but in want pulluptorefresh in my application like the pocket-sword bible application chapter loading pull-up for next-chapter and pulldown for previous chapter,i done the ordinary pulldown method,but i want pull-up,i tried to customize the existing pulldown code but no luck,i tried more than 4 days for this. i want to implement pull-up below the footer just like the pulldown just-above the header.
anyone have any idea about this please help me.
Kind regards Nipin.
- (void)addPullToRefreshHeader {
refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 - REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
refreshHeaderView.backgroundColor = [UIColor clearColor];
refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, REFRESH_HEADER_HEIGHT)];
refreshLabel.backgroundColor = [UIColor lightGrayColor];
refreshLabel.font = [UIFont boldSystemFontOfSize:16.0];
refreshLabel.textColor = [UIColor whiteColor];
refreshLabel.textAlignment = UITextAlignmentCenter;
refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"arrow.png"]];
refreshArrow.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 27) / 2,
(REFRESH_HEADER_HEIGHT - 44) / 2,
27, 44);
refreshSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
refreshSpinner.frame = CGRectMake((REFRESH_HEADER_HEIGHT - 20) / 2, (REFRESH_HEADER_HEIGHT - 20) / 2, 20, 20);
refreshSpinner.hidesWhenStopped = YES;
[refreshHeaderView addSubview:refreshLabel];
[refreshHeaderView addSubview:refreshArrow];
[refreshHeaderView addSubview:refreshSpinner];
[self.table addSubview:refreshHeaderView];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (isLoading) return;
isDragging = YES;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (isLoading) {
// Update the content inset, good for section headers
if (scrollView.contentOffset.y > 0)
self.table.contentInset = UIEdgeInsetsZero;
else if (scrollView.contentOffset.y >= -REFRESH_HEADER_HEIGHT)
self.table.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (isDragging && scrollView.contentOffset.y < 0) {
// Update the arrow direction and label
[UIView beginAnimations:nil context:NULL];
if (scrollView.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
// User is scrolling above the header
refreshLabel.text = #"Release to previous chapter...";
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
} else { // User is scrolling somewhere within the header
refreshLabel.text = #"Pull down to previous chapter..";
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
}
[UIView commitAnimations];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (isLoading) return;
isDragging = NO;
if (scrollView.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
// Released above the header
[self startLoading];
}
}
- (void)startLoading {
isLoading = YES;
delegate.selectedChapter = [NSString stringWithFormat:#"%d",[delegate.selectedChapter intValue] + 1];
[delegate reloadVerses];
[self resetReadViewToVerse:1];
// Show the header
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
self.table.contentInset = UIEdgeInsetsMake(REFRESH_HEADER_HEIGHT, 0, 0, 0);
refreshLabel.text = #"Loading...";
refreshArrow.hidden = YES;
[refreshSpinner startAnimating];
[UIView commitAnimations];
// Refresh action!
[self refresh];
}
- (void)stopLoading {
isLoading = NO;
// Hide the header
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDidStopSelector:#selector(stopLoadingComplete:finished:context:)];
self.table.contentInset = UIEdgeInsetsZero;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
[UIView commitAnimations];
}
- (void)stopLoadingComplete:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// Reset the header
refreshLabel.text =#"Pull down to previous chapter..";
refreshArrow.hidden = NO;
[refreshSpinner stopAnimating];
}
- (void)refresh {
// This is just a demo. Override this method with your custom reload action.
// Don't forget to call stopLoading at the end.
[self performSelector:#selector(stopLoading) withObject:nil afterDelay:2.0];
}
I dont know exactly about your task. But try out following code which identifies the scrollPosition of UITableView :
NSIndexPath* ipath = [NSIndexPath indexPathForRow: cells_count-1 inSection: sections_count-1];
[tableView scrollToRowAtIndexPath: ipath atScrollPosition: UITableViewScrollPositionTop animated: YES]
For more reference go to Link
Related
I have a subview named courseOptionsView that I want to show and hide with buttons and under certain conditions. When I use a swipe gesture the view works and is positioned correctly, but when I make the exact same call to the function with another button it repositions it, but it repositions it to the original position it was in instead of the coordinates I'm sending. :/ I'm stumped.
*edit
It seems that when I ++ or -- from cHNumber it resets subview. Any ideas?
IBOutlet UIView *courseOptionsView;
- (IBAction)nextHole:(id)sender;
- (IBAction)showCourseOptionsView:(id)sender;
- (IBAction)hideCourseOptionsView:(id)sender;
//show and hide functions
-(void) showCourseOptions{
if(activeRound){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[courseOptionsView setFrame:CGRectMake(50, 44, 200, 455)];
}
}
-(void) hideCourseOptions{
if(activeRound){
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[courseOptionsView setFrame:CGRectMake(-200, 44, 200, 455)];
}
}
// swipe calls
- (IBAction)showCourseOptionsView:(id)sender {
[self showCourseOptions];
}
- (IBAction)hideCourseOptionsView:(id)sender {
[self hideCourseOptions];
}
//button call
- (IBAction)nextHole:(id)sender
{
int totalStrokes = 0;
int totalPlusMinus = 0;
//[courseOptionsView setFrame:CGRectMake(0, 44, 200, 455)];
//[self showCourseOptions];
//save current hole
if(cHStrokes != [[currentRound objectForKey:[NSString stringWithFormat:#"hole%i",cHNumber]] intValue] ||
cHPutts != [[currentRound objectForKey:[NSString stringWithFormat:#"hole%i_putts",cHNumber]] intValue]){
[self saveCurrentHole];
}
// calculate and display +/- and strokes
for (int i = 0; i < ([currentRound count]/2); i++){
totalStrokes += [[currentRound objectForKey:[NSString stringWithFormat:#"hole%i",i+1]] intValue];
totalPlusMinus += [[[selectedScoreCardData objectAtIndex:0] objectForKey:[NSString stringWithFormat:#"hole%i_par",i+1]] intValue];
}
totalPlusMinus = totalStrokes - totalPlusMinus;
self.totalStrokesLabel.text = [NSString stringWithFormat:#"%i", totalStrokes];
self.totalPlusMinusLabel.text = [NSString stringWithFormat:#"%i",totalPlusMinus];
//set to next hole
/*-------------------
| SHOW VIEW HERE
--------------------*/
if(cHNumber == 17){
self.nextHoleButton.enabled = NO;
[self showCourseOptions];
}
if(cHNumber == 1){
self.prevHoleButton.enabled = YES;
}
cHNumber ++;
self.cHNumberLabel.text = [NSString stringWithFormat:#"%i", cHNumber];
[self populateScoreCard];
[strokePickerView reloadAllComponents];
if(([currentRound count]/2) < cHNumber){
[strokePickerView selectRow:cHStrokes - 1 inComponent:0 animated:YES];
[strokePickerView selectRow:0 inComponent:1 animated:YES];
}else{
[strokePickerView selectRow:[[currentRound objectForKey:[NSString stringWithFormat:#"hole%i",cHNumber]] intValue] - 1 inComponent:0 animated:YES];
[strokePickerView selectRow:[[currentRound objectForKey:[NSString stringWithFormat:#"hole%i_putts",cHNumber]] intValue] inComponent:1 animated:YES];
}
}
I think that maybe after you position the view you are calling another function that changes the layout again. A possible candidate is populateScoreCard.
How to accomplish the UISearchBar scrolling effect like Instagram.app? The UISearchBar is scrolling up while the UITableView is scrolling up. The UISearchBar stop scroll down when it's origin.y equals to 0;
My solution is as following:
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTableview.delegate = self;
self.myTableview.dataSource = self;
self.mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, searchBarHeight)];
[self.myTableView setContentInset:UIEdgeInsetsMake(searchBarHeight, 0, 0, 0)];
[self.myTableView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint offset = scrollView.contentOffset;
float move = offset.y + searchBarHeight;
if (move > -2*searchBarHeight && move <3*searchBarHeight) {
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAllowUserInteraction
animations:^{
CGRect searchBarFrame = self.mySearchBar.frame;
searchBarFrame.origin.y = MIN(MAX(-move, -searchBarHeight), 0);
[self.mySearchBar setFrame:searchBarFrame];
}
completion:^(BOOL f) {
}];
}
}
make a instance of UISearchBar and set it as tableView Header View
[tableView setTableHeaderView:yourSearchBar];
it will now scroll with tableView
I am having problem in Orientation for ios6. same code is working fine for ios5 or 5.1.
I have used - (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations as per the ios6 standard. But still "willRotateToInterfaceOrientation" and "didRotateToInterfaceOrientation" is not getting called.
Here is my code:--
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
CGRect frame;
int viewAlpha;
lastOrientation = toInterfaceOrientation;
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
viewAlpha = 1;
[MovieControlContainerLandscape setHidden:YES];
if (isDauntless) {
[self.navigationController setNavigationBarHidden:NO animated:YES];
} else {
[self.navigationController setNavigationBarHidden:NO];
}
frame = iPad ? CGRectMake(0, 88, 768, 432) : CGRectMake(0, 88, 320, 180);
[movieContainer removeGestureRecognizer:toggleMediaControl];
}
else
{
[PromptToBuy dismissWithClickedButtonIndex:0 animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
viewAlpha = 0;
[MovieControlContainerLandscape.layer setCornerRadius:22];
[MovieControlContainerLandscape.subviews.lastObject addSubview:[MediaControls use]];
if (isDauntless) {
[self.navigationController setNavigationBarHidden:YES animated:YES];
} else {
[self.navigationController setNavigationBarHidden:YES];
}
frame = iPad ? CGRectMake(0, 0, 1024, 768) : CGRectMake(0, 0, 480, 320);
[movieContainer addGestureRecognizer:toggleMediaControl];
if (isDauntless) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
}
if(TSFullScreen)
{
[movieContainer setAlpha:1];
}
if (isDauntless) {
[UIView commitAnimations];
}
}
[viewContainer setAlpha:viewAlpha];
// Size the overlay view for the current orientation.
[movieContainer setFrame:frame];
}
}
/* Sent to the view controller after the user interface rotates. */
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(fromInterfaceOrientation))
if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(fromInterfaceOrientation))
{
float duration = .5;
if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
if (isDauntless) {
[UIView transitionWithView:movieContainer duration:duration options:UIViewAnimationOptionTransitionNone animations:^{
/* Move movie view to parent center. */
[self.moviePlayerController.view setCenter:movieContainer.center];
} completion:^(BOOL finished) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
CGRect frame = movieContainer.frame;
/* Size movie view to fit parent view. */
frame.origin.y = 0;
[self.moviePlayerController.view setFrame:frame];
[UIView commitAnimations];
CGPoint center = CGPointMake(movieContainer.center.x, -50);
[MovieControlContainerLandscape setTag:0];
[MovieControlContainerLandscape setHidden:NO];
[MovieControlContainerLandscape setCenter:center];
[self toggleMovieController];
}];
} else {
CGRect frame = movieContainer.frame;
/* Size movie view to fit parent view. */
frame.origin.y = 0;
[self.moviePlayerController.view setFrame:frame];
CGPoint center = CGPointMake(movieContainer.center.x, -50);
[MovieControlContainerLandscape setTag:0];
[MovieControlContainerLandscape setHidden:NO];
[MovieControlContainerLandscape setCenter:center];
[self toggleMovieController];
}
}
else
{
if (!isDauntless) {
[MovieControlContainer setFrame:CGRectMake(0, 44, 768, 68)];
}
[MovieControlContainer addSubview:[MediaControls use]];
//NSLog(#"MovieControlContainer is %#, MovieControlContainer subviews: %#",MovieControlContainer,[MovieControlContainer subviews]);
if (isDauntless) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
}
if(TSFullScreen){
[movieContainer setAlpha:0];
}
CGRect frame = movieContainer.frame;
/* Size movie view to fit parent view. */
frame.origin.y = 0;
[self.moviePlayerController.view setFrame:frame];
if (isDauntless) {
[UIView commitAnimations];
}
}
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return !mediaTypeIsAudio && isOrientationSupported;
}
//----supported method for ios6--------//
- (BOOL) shouldAutorotate
{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}
//i have set the rootviewcontroller in appdelegate file
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController.
Please help me to take out from this problem. I am not able to find the solution for this.Thanks in Advance !!.
In ios6 you have to use this method for vieworientation
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskAll;
}
And check my answer Link
I have 5 pictures inside an infinite scrollView.
So in order to make that scrollView infinite/circular I positioned my images like this:
5 1 2 3 4 5 1
meaning: last picture first picture second picture.....last picture first picture
And in order for it to become infinite I have the following code:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if(self.scrollView.contentOffset.x == 0){
[self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];
}
else if (self.scrollView.contentOffset.x == self.view.frame.size.width*(pathImages.count+1)) {
[self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];
}
}
which means that when I'm at the last picture the contentOffset of the scrollView is set to go to the first picture-in this way I get an infinite scrollView.
What I wanted next was for my scrollView to slide automatically-for this I set a timer which calls one method-onTimer:
- (void) onTimer{
NSLog(#"flip pages");
if(h < pathImages.count*self.view.frame.size.width)
{
h+= self.view.frame.size.width;
}
else
{
h=self.view.frame.size.width;
}
if(self.scrollView.contentOffset.x == 0){
[self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width*pathImages.count, 0, self.view.frame.size.width, self.view.frame.size.height) animated:NO];
}
if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)
{
[self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];
}
else
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); }
completion:NULL];
}
This magic line:
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ self.scrollView.contentOffset = CGPointMake(h, 0); }
completion:NULL];
does the scoll automatically with animation.
Everything is great except this:
after I view the last picture I should set the offset of scroll view in order to get back to the first picture with animation.
Well if I do that:
if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)
{
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ [self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO]; }
completion:NULL];
}
after the last picture is viewed in order to get to the first picture...it loops through all the other pictures.
What I want is this:after I view the last picture to get me back to the first picture which should be loaded on screen using animation, but without viewing all the other pictures between them.Thanks
If I see this correctly, the problem is, that you again use the animation to scroll the view back to zero position. I believe you need to modify the last bit of code you posted to something like this:
if (self.scrollView.contentOffset.x == self.view.frame.size.width*pathImages.count)
{
[self.scrollView scrollRectToVisible:CGRectMake(self.view.frame.size.width,0 ,self.view.frame.size.width, self.view.frame.size.height) animated:NO];//no animation on returning
[self onTimer];//even if this code is already inside method "onTimer"
}
Rather then what you are doing try using a scrollview that displays only 3 to 5 images at the time (if they are fullscreen). If you will have many images in your application, it will crash because of high memory consumption. Try playing with this test example that does nearly what you want:
HEADER:
#import <Foundation/Foundation.h>
#interface IScrollView : UIScrollView <UIScrollViewDelegate> {
NSMutableArray *imagePaths;
UIImageView *imageViews[3];
NSInteger currentImage;
NSTimer *animationTimer;//weak link
}
#end
SOURCE:
#import "IScrollView.h"
#implementation IScrollView
- (UIImage *)imageFromResourcesWithName:(NSString *)name {
UIImage *ret = [[UIImage alloc] initWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:name]];
return [ret autorelease];
}
- (id)initWithFrame:(CGRect)frame {
if((self = [super initWithFrame:frame])) {
imagePaths = [[NSMutableArray alloc] init];
[imagePaths addObject:#"imag1.png"];
[imagePaths addObject:#"imag2.png"];
[imagePaths addObject:#"imag3.png"];
[imagePaths addObject:#"imag4.png"];
[imagePaths addObject:#"imag5.png"];
imageViews[0] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*0, .0f, 320.0f, 480.0f)];
imageViews[1] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*1, .0f, 320.0f, 480.0f)];
imageViews[2] = [[UIImageView alloc] initWithFrame:CGRectMake(320.0f*2, .0f, 320.0f, 480.0f)];
[self addSubview:imageViews[0]];
[self addSubview:imageViews[1]];
[self addSubview:imageViews[2]];
imageViews[0].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:0]];
imageViews[1].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:1]];
imageViews[2].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:2]];
currentImage = 1;
self.contentOffset = CGPointMake(320.0f*currentImage, .0f);
self.contentSize = CGSizeMake(3.0f*320.0f, 480.0f);
self.delegate = self;
animationTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:#selector(scrollFragment) userInfo:nil repeats:YES];
}
return self;
}
- (void)repositionIfNeeded {
CGFloat offsetX = self.contentOffset.x;
NSInteger iCount = [imagePaths count];
if(offsetX > 320.0f*1.75f) {
self.contentOffset = CGPointMake(offsetX-320.0f, .0f);
imageViews[0].image = imageViews[1].image;
imageViews[1].image = imageViews[2].image;
NSInteger imageToLoad = currentImage+2;
if(imageToLoad>iCount-1)
imageToLoad -= iCount;
imageViews[2].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]];
currentImage++;
if(currentImage>iCount-1)
currentImage -= iCount;
}
else if(offsetX < 320.0f*.25f) {
self.contentOffset = CGPointMake(offsetX+320.0f, .0f);
imageViews[2].image = imageViews[1].image;
imageViews[1].image = imageViews[0].image;
NSInteger imageToLoad = currentImage-2;
if(imageToLoad<0)
imageToLoad += iCount;
imageViews[0].image = [self imageFromResourcesWithName:[imagePaths objectAtIndex:imageToLoad]];
currentImage--;
if(currentImage<0)
currentImage += iCount;
}
}
- (void)scrollFragment {
self.contentOffset = CGPointMake(self.contentOffset.x+1.0, .0f);
[self repositionIfNeeded];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self repositionIfNeeded];
}
- (void)dealloc {
[imageViews[0] release];
[imageViews[1] release];
[imageViews[2] release];
[imagePaths release];
}
#end
I am trying to set multiple image on different position this is my code anyone help me to set imageview on different position.
- (void)viewDidLoad
{
[super viewDidLoad];
frameX = 45.0f;
frameY = 60.0f;
imagearr = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"King2.png"],
[UIImage imageNamed:#"3.png"],[UIImage imageNamed:#"queen.png"],
[UIImage imageNamed:#"King.png"],nil];
}
-(IBAction)hidebtn:(id)sender
{
[btn setHidden:TRUE];
[self setCards];
}
-(void)setCards
{
CGFloat dx = self.view.frame.size.width/2;
CGFloat dy = self.view.frame.size.height/2;
[cards setAnimationImages:imagearr];
CGRect frame = cards.frame;
frame.size.width = frameX;
frame.size.height = frameY;
[cards setFrame:frame];
cards.animationRepeatCount = 1;
for (int i=0; i<5;i++)
{
[UIView beginAnimations:#"Move" context:nil];
[UIView setAnimationDuration:0.3];
switch (i)
{
- (void)viewDidLoad
{
[super viewDidLoad];
frameX = 45.0f;
frameY = 60.0f;
imagearr = [[NSArray alloc] initWithObjects:[UIImage imageNamed:#"King2.png"],
[UIImage imageNamed:#"3.png"],[UIImage imageNamed:#"queen.png"],
[UIImage imageNamed:#"King.png"],nil];
}
-(IBAction)hidebtn:(id)sender
{
[btn setHidden:TRUE];
[self setCards];
}
-(void)setCards
{
CGFloat dx = self.view.frame.size.width/2;
CGFloat dy = self.view.frame.size.height/2;
[cards setAnimationImages:imagearr];
CGRect frame = cards.frame;
frame.size.width = frameX;
frame.size.height = frameY;
[cards setFrame:frame];
cards.animationRepeatCount = 1;
for (int i=0; i<5;i++)
{
[UIView beginAnimations:#"Move" context:nil];
[UIView setAnimationDuration:0.3];
switch (i)
{
case 0:
[cards setCenter:CGPointMake(dx, dy-120.0)];
cards.transform = CGAffineTransformMakeRotation(0);
break;
default:
break;
}
[self.view addSubview:cards];
[UIView commitAnimations];
}
default:
break;
}
[self.view addSubview:cards];
[UIView commitAnimations];
}
You are adding subviews too late, you can't animate what is not on screen. Add them before you start animations on some position then animate to the target position.