Page curl up - for landscape left and landscape right - xcode

I am trying to create a page turn application in xcode. The page turn works fine for landscape right but for landscape left, the page curl happens from the left. I added a container view and then the page curl on landscape left started happening from the bottom but not from right.
I found some suggestions here (http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef) and here (http://stackoverflow.com/questions/4780488/i-want-to-use-animation-to-imageview-using-uianimationtransitioncurl-right-or-lef)
but these both suggestions were with old style of page transition code and not with the block code. I tried to modify these with new block style code but it is not working for me.
I am attaching my code here:
- (void)viewDidLoad
{
UIImage *img = [UIImage imageNamed:#"s1p1.png"];
currentView.image = img;
img = [UIImage imageNamed:#"s1p2.png"];
swapView.image = img;
UISwipeGestureRecognizer *nextPage;
nextPage = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(turnPage)] autorelease];
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft) {
[nextPage setDirection:UISwipeGestureRecognizerDirectionRight];
}
else {
[nextPage setDirection:UISwipeGestureRecognizerDirectionLeft];
}
[self.view addGestureRecognizer:nextPage];
[super viewDidLoad];
}
-(void) turnPage
{
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)
{
NSLog(#"landscapeleft");
mainView.transform = CGAffineTransformMakeRotation(M_PI);
currentView.transform = CGAffineTransformMakeRotation(-M_PI);
swapView.transform = CGAffineTransformMakeRotation(-M_PI);
[UIView transitionWithView:mainView
duration:1
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
currentView.hidden = YES;
swapView.hidden = NO;
}
completion:^(BOOL finished){
UIImage *temp = [currentView.image retain];
currentView.image = swapView.image;
swapView.image = temp;
[temp release];
currentView.hidden = NO;
swapView.hidden = YES;
}];
}
else
{
NSLog(#"landscaperight");
[UIView transitionWithView:self.view
duration:1
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
currentView.hidden = YES;
swapView.hidden = NO;
}
completion:^(BOOL finished){
UIImage *temp = [currentView.image retain];
currentView.image = swapView.image;
swapView.image = temp;
[temp release];
currentView.hidden = NO;
swapView.hidden = YES;
}];
}
}
where I have two views: the self.view is the primary view from the window and then the mainView is my container view. currentView and SwapView are imageviews.
Any thoughts on this? Many thanks for reviewing this.

Related

Label/Text in Xcode Appears Blurry

I am trying to make a preferences view with lots of text. I cannot figure out why the text is blurry when i run the project, even though the interface builder is very sharp and clear. Here is a picture. [1]: http://i.stack.imgur.com/EQl6D.png
here is the code for the views:
#implementation SKMainWindowController
-(NSRect)newFrameForNewContentView:(NSView*)view {
NSWindow *window = [self window];
NSRect newFrameRect = [window frameRectForContentRect:[view frame]];
NSRect oldFrameRect = [window frame];
NSSize newSize = newFrameRect.size;
NSSize oldSize = oldFrameRect.size;
NSRect frame = [window frame];
frame.size = newSize;
frame.origin.y -= (newSize.height - oldSize.height);
return frame;
}
-(NSView *)viewForTag:(int)tag {
NSView *view = nil;
switch (tag) {
case 0: default:
view = welcome;
break;
case 1:
view = status;
break;
case 2:
view = power;
break;
case 3:
view = preferences;
break;
case 4:
view = about;
break;
}
return view;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)item {
if ([item tag] == currentViewTag) return NO;
else return YES;
}
-(void)awakeFromNib {
[[self window] setContentSize:[welcome frame].size];
[[[self window] contentView] addSubview:welcome];
[[[self window] contentView] setWantsLayer:NO];
}
-(IBAction)switchWelcome:(id)sender {
int tag = [sender tag];
NSView *view = [self viewForTag:tag];
NSView *previousView = [self viewForTag:currentViewTag];
currentViewTag = tag;
NSRect newFrame = [self newFrameForNewContentView:view];
[NSAnimationContext beginGrouping];
if ([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask)
[[NSAnimationContext currentContext] setDuration:1.0];
[[[[self window] contentView] animator] replaceSubview:previousView with:view];
[[[self window] animator] setFrame:newFrame display:YES];
[NSAnimationContext endGrouping];
[welcomeButton setState:NSOnState];
[statsButton setState:NSOffState];
[powerButton setState:NSOffState];
}
I've tried changing the text fields into code by doing things like [textField setStringValue:#""];, but with no luck it is still blurry. Thanks for any help. PS: This is for cocoa, not iOS.
Found the answer, ended up being the stupid visual effect view not cooperating. Simple fix was to set the visual effect view to within the window, and set as inactive. (although there is now no point in having a visual effect view.)

Issue with UITabBar button, TabBar button becomes un clickable

I am creating a view with UINavigationBar and UITabBar. I have added a button on tab bar, on button click, i am hiding tab bar and show tool bar at the bottom. My code is written for current as well as previous iOS versions. I am using this code self.edgesForExtendedLayout = UIRectEdgeNone; for iOS7 this is my code :
- (void)hideTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;enter code here
[UIView animateWithDuration:0.5
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds);
tabBar.frame = tabFrame;
// CGRect contentFrame = content.frame;
// contentFrame.size.height -= tabFrame.size.height;
content.frame = window.bounds;
}];
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
CGRect frame = tbl_AllFiles.frame;
frame.size.height -=tabBar.frame.size.height;
tbl_AllFiles.frame = frame;
}
}
- (void)showTabBar {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView
UIView *window = parent.superview;
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
CGRect frame = tbl_AllFiles.frame;
frame.size.height +=tabBar.frame.size.height;
tbl_AllFiles.frame = frame;
}
[UIView animateWithDuration:0.5
animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
tabBar.frame = tabFrame;
CGRect contentFrame = content.frame;
contentFrame.size.height -= tabFrame.size.height;
content.frame = contentFrame;
}];
}
- (void)loadToolBar {
toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
moveButton = [UIButton buttonWithType:UIButtonTypeCustom];
[moveButton setFrame:CGRectMake(10, 10, 120, 25)];
[moveButton setBackgroundColor:[UIColor redColor]];
[moveButton setTitle:#"Move" forState:UIControlStateNormal];
[moveButton addTarget:self action:#selector(moveFile_Folder:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *moveItem = [[[UIBarButtonItem alloc] initWithCustomView:moveButton] autorelease];
moveItem.style = UIBarButtonItemStyleBordered;
NSArray *items = [NSArray arrayWithObjects:moveItem, nil];
toolbar.items = items;
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
{
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
}
else
{
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
}
[self.view addSubview:toolbar];
[toolbar bringSubviewToFront:self.view];
}
My issue is on button clicked hideTabBar and loadToolBar methods are called. Everything is working fine, except my button is un-clickable now on toolbar.
Please help me.
i had a similar issue if your viewcontroller is not the root view controller iOS doesn't get the view frame.
Add this line to your viewcontroller in viewdidload,
self.view.frame = [UIScreen mainScreen].bounds;
hope it helps

how to show images as a gridview like format in uiscrollview in ios?

its just a week that am into ios devlopement and am facing some problem that i cant show the images in scrolview with gridview format...i dont know how to set the frame size to show images in proper gridview format..
here is my code
that add 5 images in scrollview
for(int i=1;i<6;i++)
{
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x+0, 0, 320, 460)];
[image setImage:[UIImage imageNamed:[NSString stringWithFormat:#"e1%d.png",i]]];
[scr addSubview:image];
x+=320;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.delegate = self;
image.userInteractionEnabled = YES;
[image addGestureRecognizer:tapGesture];
}
scr.pagingEnabled=YES;
scr.contentSize = CGSizeMake(320*5, 300);
[self.view addSubview:scr];
but all 5 images shows in one horizontal line but i want to show in every line 2 images.
here is the solution, i've implemented it in my app. Here is my code sv_port is my scrollView. Download SDWebImageDownloader class files and import it in your project. Add
relevant framework in your project. like imageIO.framework, QuartzCore
if your images are not fetching from url, then u dont need to use asyncImage view., so dont need to download SDWebImageDownloader.
Now, in your .m add
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
#import "SDWebImageCompat.h"
//function for adding image in your scrollview
-(void)populateImages
{
int x=6,y=6;
for(UIView * view in sv_port.subviews)
{
if([view isKindOfClass:[UIImageView class]])
{
[view removeFromSuperview]; view = nil;
}
if([view isKindOfClass:[UIButton class]])
{
[view removeFromSuperview]; view = nil;
}
}
for(int p=0;p<[Manufacturer count];p++)
{
UIButton *btnImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
btnImageButton.frame = CGRectMake(x,y,70,70);
[btnImageButton setTag:p];
[btnImageButton addTarget:self action:#selector(nextview:) forControlEvents:UIControlEventTouchUpInside];
UIActivityIndicatorView *spinny = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinny.frame=CGRectMake(btnImageButton.frame.origin.x+25,btnImageButton.frame.origin.y+25, 20, 20);
spinny.backgroundColor=[UIColor clearColor];
[spinny startAnimating];
[sv_port setScrollEnabled:YES];
[sv_port addSubview:spinny];
UIImageView *asyncImageView = [[[UIImageView alloc] initWithFrame:btnImageButton.frame] autorelease];
asyncImageView.backgroundColor=[UIColor clearColor];
CALayer *layer;
layer = asyncImageView.layer;
layer.borderWidth = 0.5;
layer.cornerRadius = 5;
layer.masksToBounds = YES;
[asyncImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#", yourUrl] ] placeholderImage:[UIImage imageNamed:nil] options:0 andResize:CGSizeMake(btnImageButton.frame.size.width,btnImageButton.frame.size.height) withContentMode:UIViewContentModeScaleAspectFit];
asyncImageView.contentMode = UIViewContentModeScaleAspectFit;
[sv_port addSubview:btnImageButton];
[sv_port addSubview:asyncImageView];
int imgCntPort=0;
imgCntPort=(sv_port.frame.size.width/(asyncImageView.frame.size.width));
//NSLog(#"imgport %d",imgCntPort);
if((p+1)%imgCntPort==0)
{
x=5;
y=y+80;
}
else
{
x=x+80;
}
}
sv_port.contentSize = CGSizeMake(0, y);
glob_x =0; glob_y =y;
}
By this code you will get 4 images in a row., By the change co-Ordiante of x and y you can maintain number of images per row to display.
Hope this helps. Thanks

Posting images from camera roll to facebook in xcode 4.5

I've got some functionality set up. But I'm lost on where to go from here. I can probably figure out what to do with facebook once I know how to actually use the images. I tried saving the image into NSDictionary and then redirecting to a different View Controller, but it won't let me redirect from within the imagePickerController method. So anybody have any idea how to use the image selected from camera roll?
My next idea was to save it in the NSDictionary and then just have a statement checking to see if the NSdictionary value changed but that's not an efficient way of doing it at all.
EDITED below to include the answer provided, but nothing happens, no image displays or anything. What am I missing?
- (void) useCameraRoll
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
newMedia = NO;
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info
objectForKey:UIImagePickerControllerOriginalImage];
NSLog(#"image:%#",image);
displayPhoto.image = image;
[displayPhoto setFrame:CGRectMake(0, 0, 320, 480)];
[[self view] addSubview:displayPhoto];
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
Assuming you have called this from a view controller with a button that you have created, why not just add a UIImageView onto your view controller? Call it myPhotoImageView or something like that and then in the didFinishPickingMediaWithInfo method, just add the following line of code after
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
as
myPhotoImageView.image = image;
To size the image view so that the aspect looks nice do this.
CGSize size = image.size;
CGRect photoFrame;
if (size.width > size.height)
{
// Landscape
CGFloat scaleFactor = 320 / size.width;
photoFrame = CGRectMake(0, 0, 320, size.height*scaleFactor);
}
else
{
// Portrait
CGFloat scaleFactor = 320 / size.height;
photoFrame = CGRectMake(0, 0, size.width*scaleFactor, 320);
}
myPhotoImageView.frame = photoFrame;

Reset nested uiscrollview zooms when scroll ends

Nested uiscrolls in a larger uiscroll need to, when zoomed, reset zoom level when they are off screen. I am trying to reset all of them when the scrolling ends but no luck. Any ideas?
myScrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
myScrollview.pagingEnabled = YES;
myScrollview.scrollEnabled =YES;
myScrollview.clipsToBounds = NO;
myScrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;
myScrollview.showsHorizontalScrollIndicator = YES;
myScrollview.backgroundColor = [UIColor blackColor];
myScrollview.delegate = self;
NSInteger viewcount=4;
NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:#"01.png"],[UIImage imageNamed:#"02.png"],[UIImage imageNamed:#"03.png"],[UIImage imageNamed:#"04.png"],nil];
for (int i = 0; i <viewcount; i++)
{
CGFloat x = i * self.view.frame.size.width;
subView = [[UIScrollView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];
[subView setBackgroundColor:[UIColor blackColor]];
[subView setCanCancelContentTouches:NO];
subView.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
subView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
aImageView = [[UIImageView alloc ] initWithImage:[images objectAtIndex:i]];
[self.aImageView setTag:viewcount];
[subView addSubview:aImageView];
[subView setContentSize:CGSizeMake(aImageView.frame.size.width, subView.frame.size.height)];
subView.minimumZoomScale = 1;
subView.maximumZoomScale = 3;
subView.delegate = self;
[subView setScrollEnabled:YES];
subView.contentSize = aImageView.frame.size;
[myScrollview addSubview:subView];
}
myScrollview.contentSize = CGSizeMake(self.view.frame.size.width*viewcount,self.view.frame.size.height);
[self.view addSubview:myScrollview];
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
NSLog (#"test");
UIView * view = nil;
view = [subView viewWithTag:0];
//return view;
return [scrollView.subviews objectAtIndex:0];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(#"Did scroll");
[self resetImageZoom];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
= NSLog(#"Did end decal");
[self resetImageZoom];
}
-(void)resetImageZoom {
NSLog(#"Resetting any image zoom");
for(UIView *view in [myScrollview subviews]) {
//if([view isKindOfClass:[UIScrollView class]]) {
//[(UIScrollView*)view setZoomScale:1.0 animated:NO];
//}
view.transform = CGAffineTransformIdentity;
}
}
That did it...
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(#"Did end dece");
for (UIView *view in scrollView.subviews) {
if([view isKindOfClass:[UIScrollView class]]) {
[(UIScrollView*)view setZoomScale:1.0 animated:NO];
}
}
}

Resources