iOS FadeIn/FadeOut during paging - ios

I have an UIScrollView with views inside that I can scroll horizontally. During the scroll I would like to add a fade out on the view which is going out of the screen and a fade in on the view which is going in the screen.
Here my code :
for (int i = 0; i <textEntries.count; i++)
{
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i + 5;
frame.size.width = self.scrollView.frame.size.width - 10;
frame.size.height = self.scrollView.frame.size.height - 10;
self.scrollView.pagingEnabled = YES;
UIView *subview = [[UIView alloc] initWithFrame:frame];
if([[colorEntries objectAtIndex:i] isEqualToString:#"violet"]){
subview.backgroundColor = [UIColor colorWithRed:(147/255.0) green:(90/255.0) blue:(255/255.0) alpha:1];
} else {
subview.backgroundColor = [UIColor colorWithRed:(100/255.0) green:(166/255.0) blue:(255/255.0) alpha:1];
}
subview.layer.cornerRadius = 5;
[self.scrollView addSubview:subview];
UITextView *noteLabel = [[UITextView alloc] init];
noteLabel.frame = CGRectMake(0, 0, self.scrollView.frame.size.width - 20, self.scrollView.frame.size.height -20);
noteLabel.text = [textEntries objectAtIndex:i];
noteLabel.userInteractionEnabled = NO;
noteLabel.backgroundColor = [UIColor clearColor];
noteLabel.contentInset = UIEdgeInsetsMake(20,20,20,20);
noteLabel.font = [UIFont fontWithName:#"HelveticaNeue-Bold" size:40];
[noteLabel setTextColor:[UIColor whiteColor]];
[subview addSubview:noteLabel];
[noteLabel addObserver:self forKeyPath:#"contentSize" options:(NSKeyValueObservingOptionNew) context:NULL];
}
Could you help me to build this fadeIn/FadeOut effect ?
Thanks!

Related

How to add Date Picker in Horizontal paging scroll view?

I have Created UIScrollview with Paging, But i want to add Date picker in some pages. But Date picker scroll not working.
NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
CGRect pickerFrame = CGRectMake(0,100,100,100);
UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[myPicker addTarget:self action:#selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:myPicker];
[myPicker release];
[self.scrollView addSubview:subview];
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = colors.count;
Instead of adding the picker view to self.view, add it to self.scrollView
[self.scrollView addSubview:myPicker];
Or else, You can add picker view as input view to a text field,
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
//CGRect pickerFrame = CGRectMake(0,100,100,100);
myTextField = [[UITextField alloc]initWithFrame:
CGRectMake(10, 100, 300, 30)]; //if you dont want to show the text field you can change the frame to CGRectMake(0, 0, 1, 1)
myTextField.borderStyle = UITextBorderStyleRoundedRect;
myTextField.textAlignment = NSTextAlignmentCenter;
myTextField.delegate = self;
[self.view addSubview:myTextField];
UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[myPicker addTarget:self action:#selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
[myTextField setInputView:myPicker];
[self.scrollView addSubview:myTextField];
[myPicker release];
[self.scrollView addSubview:subview];
[subview release];
}
and when you want to show the picker, Call the below method [self showPickerView]
- (void)showPickerView
{
[myTextField becomeFirstResponder];
}

Quick movement change of image on swipe scrollview

In the below code when clicked on page control it moving to another Image, with an quick movement.
Need same effect of quick movement swipe on scroll View.
-(void)viewDidLoad{
pageControlBeingUsed = NO;
pageControl = [[UIPageControl alloc]init];
scrollView = [[UIScrollView alloc] init];
scrollView.delegate = self;
scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/1.6);
scrollView.bounces = true;
scrollView.showsHorizontalScrollIndicator = false;
scrollView.showsVerticalScrollIndicator = false;
NSArray *colors = [NSArray arrayWithObjects:[UIColor colorWithPatternImage:[UIImage imageNamed:#"image1"]], [UIColor colorWithPatternImage:[UIImage imageNamed:#"image2"]],[UIColor colorWithPatternImage:[UIImage imageNamed:#"image3"]],nil];
for (int i = 0; i < colors.count; i++){
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[self.scrollView addSubview:subview];
}
scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
pageControl.frame = CGRectMake(0,self.scrollView.frame.size.height+10, self.view.frame.size.width,30);
[pageControl addTarget:self action:#selector(changePage:) forControlEvents:UIControlEventValueChanged];
pageControl.currentPage = 0;
pageControl.numberOfPages = colors.count;
[self.view addSubview:pageControl];
[self.view bringSubviewToFront:pageControl];
[self.view addSubview:scrollView];
}
- (void)scrollViewDidScroll:(id)sender {
if (!pageControlBeingUsed) {
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
}
- (void)changePage:(id)sender{
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
pageControlBeingUsed = YES;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
pageControlBeingUsed = NO;
}
From above code when i click on pageControl its trigger the method changePage and move to next page, same effect need when user swipe from left to right right to left on scrollview.
#All
Just Add scrollView.pagingEnabled = YES; Issue resolved.

Not able to scroll images in iOS

I have create scrollview inside that i am displaying tiles using this i can swap images.if i take 9 images it displaying in scrollview but If i give setUserInteractionEnabled:NO means i can tiles i can swap but If i give setUserInteractionEnabled:YES then its scroll is working not tiles i can not swap image and not even touch images.Can any one tell me what is the mistake in this below code..
-(void)ViewDidLoad
{
thumbnailscrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
thumbnailscrollview.delegate = self;
thumbnailscrollview.backgroundColor = [UIColor whiteColor];
[thumbnailscrollview setUserInteractionEnabled:YES];
[thumbnailscrollview setContentSize:CGSizeMake(320.0,1600.0)];
thumbnailscrollview.showsVerticalScrollIndicator = YES;
[self.view addSubview:thumbnailscrollview];
[self createTiles];
}
- (void)createTiles {
theviewlabel=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
// [self.view addSubview:thumbnailscrollview];
[thumbnailscrollview addSubview:theviewlabel];
tileindex=0;
UIColor *tileColors[] = {
[UIColor whiteColor],
[UIColor whiteColor],
[UIColor whiteColor],
[UIColor whiteColor],
[UIColor whiteColor],
[UIColor whiteColor],
[UIColor whiteColor],
};
int tileColorCount = sizeof(tileColors) / sizeof(tileColors[0]);
int rows=([_imageCollection1 count]/3)+1;
CGRect frame;
int count=0;
for (int row = 0; row < rows; row++) {
for (int col = 0; col < TILE_COLUMNS; col++) {
if ([_imageCollection1 count] <= count) {
return;
}
int index = (row * TILE_COLUMNS) + col;
frame = CGRectMake(TILE_MARGIN + col * (TILE_MARGIN + TILE_WIDTH),
TILE_MARGIN + row * (TILE_MARGIN + TILE_HEIGHT),
TILE_WIDTH, TILE_HEIGHT);
CGRect frame2 = CGRectMake(TILE_MARGIN + col * (TILE_MARGIN + TILE_WIDTH)-12,
TILE_MARGIN + row * (TILE_MARGIN + TILE_HEIGHT)-3,
12, 12);
tileFrame[index] = frame;
Tile *tile = [[Tile alloc] init];
tile.tileIndex = index;
tile.tag=[[_buttontagcollections1 objectAtIndex:index]intValue];
tile.mRearrangeView=[_imageCollection1 objectAtIndex:count];
count++;
tileForFrame[index] = tile;
tile.frame = frame;
tile.backgroundColor = tileColors[index % tileColorCount].CGColor;
//tile.cornerRadius = 8;
tile.delegate = self;
thelabel=[[UILabel alloc]initWithFrame:frame2];
thelabel.backgroundColor=[UIColor whiteColor];
thelabel.textColor=[UIColor redColor];
thelabel.layer.cornerRadius=7;
//button.titleLabel.textAlignment = NSTextAlignmentCenter;
thelabel.textAlignment=NSTextAlignmentCenter;
thelabel.text=[NSString stringWithFormat:#"%d",tileindex
];
thelabel.font=[UIFont systemFontOfSize:13];
//[self.view.layer addSublayer:tile];
[theviewlabel addSubview:thelabel];
homeView = [[UIView alloc]initWithFrame:CGRectMake(248, -480, 72, 480)];
homeView.backgroundColor = [UIColor clearColor];
[thumbnailscrollview addSubview:homeView];
[tile setNeedsDisplay];
tileindex++;
homeView = [[UIView alloc]initWithFrame:CGRectMake(248, -480, 72, 480)];
homeView.backgroundColor = [UIColor clearColor];
[thumbnailscrollview addSubview:homeView];
[thumbnailscrollview.layer addSublayer:tile];
}
}
}
enter code herewhy are you adjusting content size BEFORE adding subviews to scroll view.Always add content size after adding all subviews to scroll view.The content size of scroll view must be larger than its superview.
what you do :
in viewDIDLoad:
thumbnailscrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x,
self.view.frame.origin.y,
self.view.frame.size.width,
self.viewframe.size.height)];
//[thumbnailscrollview setContentSize:CGSizeMake(320.0,1600.0)]; comment this line
and in createTile method, when you are all done adding your subview then set content size:
CGRect contentRect = CGRectZero;
for (UIView *view in self.thumbnailscrollview.subviews)
{
contentRect = CGRectUnion(contentRect, view.frame);
}
self.thumbnailscrollview.contentSize = contentRect.size;
it should work then.
thanks

iOS Image View turn off selection highlighting

Bit of a strange question, so i've attached a screen recording to help...
Video : https://www.dropbox.com/s/3aaefixsk8eejln/Error.mov (See past the watermark!)
My issue is that in my application when the user is at the "Preview" view and is reviewing their images, each time the image is selected, the image receives a touched overlay, which could be confusing for a user as nothing happens when touched.
I would like to disable this if possible..
Below is the example code to how the images are being displayed..
- (void)setReviewImages
{
continueButtonDisabled = YES;
downloadedImageCount = 0;
NSArray *reviewViews = scrollView.subviews;
for (IMReviewView *reviewView in reviewViews) {
[reviewView removeFromSuperview];
}
NSUInteger photoCount = [[IMLocalUser localUser] cachedPhotoCount];
if ( nPageNum == 0 ){
for (NSUInteger i = 0; i < photoCount; i++) {
CGRect frame;
frame.origin.x = scrollView.frame.size.width * i;
frame.origin.y = 65;
frame.size = CGSizeMake(scrollView.frame.size.width, 327.0f);
IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
subview.delegate = self;
subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:i];
[scrollView addSubview:subview];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * i, scrollView.frame.size.height);
UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
[self.view addSubview:headingLabel];
headingLabel.text = #"Time To Preview!";
headingLabel.textColor = [UIColor blackColor];
headingLabel.textAlignment = UITextAlignmentCenter;
headingLabel.textAlignment = NSTextAlignmentCenter;
headingLabel.tag = 10;
headingLabel.backgroundColor = [UIColor clearColor];
headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
headingLabel.hidden = NO;
headingLabel.highlighted = YES;
headingLabel.highlightedTextColor = [UIColor blackColor];
headingLabel.lineBreakMode = YES;
headingLabel.numberOfLines = 0;
}
It seems to me like IMReviewView has a UIButton subview. If so, try to set its adjustsImageWhenHighlighted property to NO.

Change text on swipe

I am creating a text jokes app what i need is i want the UITextView in swipe form like when i swipe the first joke after a gap another UITextview comes in with another joke , so far what i have done is i have manually created the UITextView ( like if there is 10 jokes then 10 uitextview ) and added them in a scroll but that is taking too much time in viewdidload method and the app takes 6,7 second to load ...
if you have anyother idea please do let me know
for (int i = 0; i < arrresult.count; i++) {
CGRect frame;
frame.origin.x = self.scrollmain.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollmain.frame.size;
// UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
// UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];
UITextView *subview = [[UITextView alloc] initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+10, 230, 120)];
UITextView *subview2 = [[UITextView alloc]initWithFrame:CGRectMake((frame.origin.x)+40,(frame.origin.y)+160,230, 120)];
subview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BG_text.png"]];
subview2.backgroundColor = [UIColor whiteColor];
[subview setFont:[UIFont boldSystemFontOfSize:14]];
[subview2 setFont:[UIFont boldSystemFontOfSize:14]];
subview.layer.cornerRadius = 10 ;
subview2.layer.cornerRadius = 10;
NSString *p = [duaobj2 dua_arabic];
NSString *b = [duaobj2 eng_trans];
subview.text = p;
subview2.text = b;
[self.scrollmain addSubview:subview];
[self.scrollmain addSubview:subview2];
subview.editable = NO;
subview2.editable = NO;
subview.textColor = [UIColor blackColor];
subview2.textColor = [UIColor blackColor];
subview.backgroundColor = [UIColor whiteColor];
subview2.backgroundColor = [UIColor whiteColor];
scrollmain.showsHorizontalScrollIndicator = NO;
CGRect frame1 = subview.frame;
CGRect frame2 = subview2.frame;
frame1.size.height = subview.contentSize.height;
frame2.size.height = subview2.contentSize.height;
subview.frame = frame1;
subview2.frame = frame2;
}
self.scrollmain.contentSize = CGSizeMake(self.scrollmain.frame.size.width * arrresult.count,self.scrollmain.frame.size.height);
scrollmain.pagingEnabled = TRUE;
scrollmain.delegate = self;
There is no need to load the subviews at the time of viewDidLoad.
You should delay this by using scrollView delegate methods.
You should create only 3 textviews at max. Current, previous and next.
On scrollViewDidScroll delegate method, you should wisely remove previously loaded textview and you should add new textview.

Resources