Adding UIAnimation - ios

I have a ScrollView with paging and I have a button which takes me to an array with image in my scrollView .. Here's my codes
-(IBAction)scrollToPage:(id)sender {
int scrollToPage = 1;
int scrollToX = 1-1;
[self.scrollView scrollRectToVisible:CGRectMake(scrollToX*self.scrollView.frame.size.width,0,self.scrollView.frame.size.width,self.scrollView.frame.size.height) animated:YES];
}
I know it's already animated but I need to add custom animation to it for example :"flip horizontal, cross dissolve, etc"
Thanks in advane

You can use the following code snippet to flip the image you have in your button pressed action method. This will allow the image to be flipped then you can play around with it to be what you want.
UIImage* sourceImage = [UIImage imageNamed:#"whatever.png"];
UIImage* flippedImage = [UIImage imageWithCGImage:sourceImage.CGImage
scale:1.0 orientation: UIImageOrientationUpMirrored];
See if this works for you.

Related

how to draw border of UITextView in IOS

I need to create an UITextView like in Image, but UITextView auto resize to content height. It is in chat message. At left-bottom and right-bottom have one arrow. But I don't know how to draw or create them in iOS. Can someone tell me how to do this? thank you very much.
Arrow in left-bottom and turn the left if messsage from another body, arrow on the right-bottom and turn the right when message from "self"
You can use the mirror effect On the image. by using same image for both sender and receiver
-(UIImage*)setBubbleImageForSender
{
UIImage *image = [UIImage imageNamed:#"sender.png"];
return image;
}
-(UIImage*)setBubbleImageForReceiver
{
UIImage *image = [UIImage imageNamed:#"sender.png"];
image = [UIImage imageWithCGImage:image.CGImage
scale:image.scale
orientation:UIImageOrientationUpMirrored];
return image;
}
The above thing will change the arrow direction for the chat app.
for resizing the height and width you can use the [imgvw resizableImageWithCapInsets:..] for the imageview and set table cell height accordingly.
Thanks

iOS 7.1 issue - Tabbar icon image is automatically resize when touch and drag on that tab button

I have this code
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"tab_pressed_home_icon"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab_home_icon"]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(8, 0, -2, 0);
which set an icon on the tab bar.
everything work fines so far until last night that i update Xcode 5.1
and run the app on ios7.1 simulator.
here is the app
now when i tap the tab bar the icon image size is decrease an when i release the finger image is back to normal.
But if i tap the icon and drag it the image is look like this (scale down).
like this
how can this happen?
is there anyway to solve this?
Thanks.
This problem was resolved by setting the imageInsets of the tabBarItem as others have mentioned. You can do this in code or you can do it in Interface Builder, it doesn't matter.
The important point is to have the top inset BE EQUAL to the bottom inset.
I had the same problem on iOS 7.1 when trying to set the Image insets by code like:
[self.tabBarItem setImageInsets:UIEdgeInsetsMake(5, 0, -5, 0)];
So I solved it using directly the Bar Item Size on my Storyboard.
Take in count that for this to work you should be assigning the image of you TabBarItem in the following way
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *myItem = [tabBar.items objectAtIndex:0];
[homeItem setFinishedSelectedImage:[UIImage imageNamed:#"A.png"]
withFinishedUnselectedImage:[UIImage imageNamed:#"B.png"]];
instead of this way
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"A.png"]
withFinishedUnselectedImage:[UIImage imageNamed:#"B.png"]];
Update
To access the Bar Item Size select directly the 'Item' element under the Scene of any of your Tab Bar Controller's child. (Image1)
my problem is similar, the tabbar icon changed it position in 7.1 update, this problem is really annoying, and I did a quick solution because I have to approve the app. Was this:
Ok I not sure that is the best solution, but for me works.
Same problem here. Also after update to iOS 7.1 and xcode 5.1 My solution: The tab bar item size was set at 4 for Bottom.(in Size inspector) I changed it to 0 like all the others and the problem was gone.
I give it up, my solution is here:
use the function to resize and make offset with UIImage
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize andOffSet:(CGPoint)offSet{
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(offSet.x, offSet.y, newSize.width-offSet.x, newSize.height-offSet.y)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
and set the tab bar item image properly:
UITabBarItem *barItem = [self.tabBarController.tabBar.items objectAtIndex:i];
CGSize size = CGSizeMake(49, 49);
CGPoint offset = CGPointMake(10, 10);
[barItem setFinishedSelectedImage:[self imageWithImage:selectedImage scaledToSize:size andOffSet:offset]
withFinishedUnselectedImage:[self imageWithImage:unSelectedImage scaledToSize:size andOffSet:offset]];
if any other solutions would be help!
My answer is based on others posted here - setting to 0 all ImageInsets in tab bar items:
for (UITabBarItem* item in self.tabBar.items)
{
[item setImageInsets: UIEdgeInsetsMake(0, 0, 0, 0)];
}
You may put a UIView on top of the tab bar, and add a UITapGestureReognizer to the UIView. When tapped, I determine where it is and call the appropriate selected item for the tabbar. Hack, but works quite nicely and lets you keep your inset values to whatever you want.
#property UIView tabBarCover;//place on top of uitabbar and give it clear color background
- (void)viewDidLoad
{
[tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[tabBarCover addGestureRecognizer:singleFingerTap];
}
Then each time the UIView is tapped, set the selected item based on where the user touched. I had 3 tab bar items, so I just did some logic for the x coordinate.
-(void) handleSingleTap:(UITapGestureRecognizer *) recognizer
{
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
//NSLog(#"tapped it %lf", location.x);
if(location.x<=105){
//1st 3rd tapped, do something
}
else if(location.x >105 && location.x<=210)
{
//do nothing, selected item stays same. this is glas
}else{
//must be in 3rd section so do that load
}
}
Hope it helps.
I spent about 3 hours of it! And I have found our mistake. it is not bug of iOS.
Note: imageInsets will not help! because this is problem with image's scale. I played 2 hours with it! and no result. it was stupid way to try solve the problem!
Please look this project http://www.raywenderlich.com/50310/storyboards-tutorial-in-ios-7-part-2
on this project Players and Gestures icons works perfectly! because there are icons for retina and non-retina.
if you have icons for both scale, then no problem. use them! everything will work fine! it was 1-variant!
2-variant. if you have only one big image and you want use for both display, then you need specify the "scale" of the resized image:
(UIImage *)thumbnailImageSize:(CGSize)size fromImage:(UIImage *)image {
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)] == YES && [[UIScreen mainScreen] scale] == 3.00) {
_scale = 3.00;
} else if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
_scale = 2.00;
} else
_scale = 1.00;
UIGraphicsBeginImageContextWithOptions(size, NO, _scale);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
My solution was to divide by 2 the x and y points, then I set it to left, right, top and bottom respectively.
try this it should do the trick and won't affect the older versions
Put the below lines in the any controller init method:
UIImage* image = [UIImage imageNamed: #"Your tabbar image name goes here"];
if ([image respondsToSelector: #selector(imageWithRenderingMode:)])
[self.tabBarItem setImage: [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
Top and bottom insets are set in your code — it should be enough to set just on of these (say, top). The reason the highlighted image gets compressed might be that the raster has different dimensions, not the same as the default image — in this case the insets make the image scale vertically.
I fixed the same problem by using this category for UIImage that create an Image from an UIView
+ (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
And then, using this method you can create a new image with the custom offset you need. (I need only Y offset).
-(UIImage *) uiNewImageForTabBar: (UIImage *) i withOffsetForY: (CGFloat) offsetY
{
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, i.size.width, i.size.height+offsetY)];
[v setBackgroundColor:[UIColor clearColor]];
[v setOpaque:NO];
UIImageView *sub = [[UIImageView alloc] initWithImage:i];
[sub setY:offsetY];
[v addSubview:sub];
return [UIImage imageWithView:v];
}

Setting an background image over an image set for a UIImageView - Objective C

I am setting images to a UIImage programmatically. But I want to also add a play button over that view. Think of Facebook in how there is a play button over the image. That is exactly what I am trying to figure out on what to do. Here is my setting of the UIImage:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg", indexPath.row]];
cell.photoView.image = img;
Suggestions, thoughts?
You can add playbutton either as a UIButton or a UIImageView and add as a subview to your photoview.
[cell.photoView addSubview:urPlayButtonView];

Show stack of images one on top of the other in iOS

I'm trying to develop a simple app that shows a stack of images: each image on top of the other. And when you swipe or click a button, the first image will disappear and the image below it will have the same size as the one that was on the top (as in the image below, but without the rotation effect)
I've tried to fetch the images and create the frame of the images at each for loop iteration:
UIImageView*picture = [[UIImageView alloc] initWithFrame:CGRectMake(40+10*i, 101-10*i, 240-20*i, 200)];
UIImage *image = [UIImage imageWithData:imageData];
picture.image = image;
[dView addSubview:picture];
and it worked. But I still can't find how to make the second image in the same size as the one that was on top of it.
CGrect nextImageFrame = nextImage.frame;
nextImageFrame.size.width = 240;
nextImageFrame.size.height = 200;
nextImage.frame = nextImageFrame;
assuming that nextImage is the image you want to show next

iOS app - Apply background image object to UIView

Can anyone help me understand how I apply a background image object to a UIView please?
I have created a background image which is a blurred version of a background and I would like to apply it to be the background of a uiView in the foreground which would ideally mask the background image.
I have the following code so far -
_blurImage = [source stackBlur:50];
[_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:[_blurImage]]];
I would like to apply the image object(_blurImage) to be the background image of _hpBlurView but i'm struggling to get it working!
At first glance, you are using too many brackets. Here is a working version of your code :
_burImage = [source stackBlur:50];
_HPBlurImage.backgroundColor = [UIColor colorWithPatternImage:_blurImage];
I can't see what stackBlur:50 returns. So start from the beginning. colorWithPatternImag takes UIImage as a parameter. So Start by adding a picture, any picture, to your application. Lets imagine that the image is called image.png. This is one way to do it:
UIImage *image = [UIImage imageNamed:#"image.png"];
_HPBlurView.backgroundColor = [UIColor colorWithPatternImage:image];
This should help to get you going.
Create an image and add to the background.:
UIImage *image = [UIImage imageNamed:#"youimage"];
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
It's that.
To make sure everything resizes properly, no matter rotation, device size and iOS version, I just set an UIImageView
//Create UIImageView
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame]; //or in your case you should use your _blurView
backgroundImageView.image = [UIImage imageNamed:#"image.png"];
//set it as a subview
[self.view addSubview:backgoundImageView]; //in your case, again, use _blurView
//just in case
[self.view sendSubviewToBack:backgroundImageView];

Resources