How to customize size of UAModalPanel? - ios

Usually I would initialize a UAModalPanel like below, and it would work fine
modalPanel = [[[UAExampleModalPanel alloc] initWithFrame:self.view.bounds withView:#"modalPanel_iPhone"] autorelease];
[self.view addSubview:modalPanel];
modalPanel.delegate = self;
[modalPanel showFromPoint:modalPanel.view.center];
but if I try changing the first line to below, I cannot click the X button to close the subview. What am I doing wrong?
modalPanel = [[[UAExampleModalPanel alloc] initWithFrame:CGRectMake(10,10,100,100) withView:#"modalPanel_iPhone"] autorelease];

I am the author of UAModalPanel. You always initialize the panel with the full sized frame of the window, so the dark mask can reach full screen. Then, if you want to adjust the panel size, you tweak the margin and padding of the panel, as shown on Step 4 in the ReadMe on the Github page.

Related

Key-Frame Animation appears fuzzy when moving Frames?

I use JazzHands to create a key frame based animation in a UIScrollView.
Here is an example. Look at the view at the top. When you move from page to page. While the animation is running the view at the top is slightly moving from left to right. The animation appears a bit fuzzy.
Here is the code taken from the example here:
IFTTTFrameAnimation *titleView1FrameAnimation = [IFTTTFrameAnimation new];
titleView1FrameAnimation.view = self.titleView1;
[self.animator addAnimation:titleView1FrameAnimation];
[titleView1FrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(1)
andFrame:self.titleView1.frame]];
[titleView1FrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(2)
andFrame:CGRectOffset(self.titleView1.frame, timeForPage(2), 0)]];
[titleView1FrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(3)
andFrame:CGRectOffset(self.titleView1.frame, timeForPage(3), 0)]];
[titleView1FrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(4)
andFrame:CGRectOffset(self.titleView1.frame, timeForPage(4), 0)]];
When running the demo take a look at the part marked with red in the following screenshot:
Edit: Here is the code containing this problem: https://github.com/steffimueller/Intro-Guide-View-for-Talk.ai
How can I make the animation running smooth and less fuzzy?
This is due to the frame rate in the JazzHands IFTTTAnimatedScrollViewController being set for non-retina displays. You need to double the number in timeForPage, and also use double the number of the contentOffset in animate, but use the original non-doubled values of timeForPage in places where you were using that for laying out the positions of views instead of using it for the animation time.
Here's a Gist of the changes you'd have to make to your example to get it working. Fixed Demo Gist
You need this method for setting the animation times:
#define timeForPage(page) (NSInteger)(self.view.frame.size.width * (page - 1) * 2.0)
And this one for setting the centers of your views based on the page dimensions:
#define centerForPage(page) (NSInteger)(self.view.frame.size.width * (page - 1))
Then you need to override the scrollViewDidScroll: method in IFTTTAnimatedScrollViewController to use double the numbers it's currently using.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[self.animator animate:(NSInteger)(scrollView.contentOffset.x * 2)];
}
We'll work on getting the JazzHands demo updated!
Before you start your animation call:
view.layer.shouldRasterize = YES; (seems that you are using objective-c so I put YES here, for swift should be true)
As soon as the animation is finished call
view.layer.shouldRasterize = NO; (seems that you are using objective-c so I put NO here, for swift should be false)
You should always use it when you animating a view
You can see more details about it in the WWDC 2012 Polishing Your Interface Rotations video (paid developer subscription needed)
I hope that helps you!
[EDIT]
Every Time you call the method animate set shouldRasterize to YES before it, like in the example bellow:
titleView1FrameAnimation.view.layer.shouldRasterize = YES;
[self. titleView1FrameAnimation animate:scrollView.contentOffset.x];
I've messed around a bit with the code and it seems that keeping those top views in place while the scrollview is scrolling made it jiggle left and right.
What I did is take out the title view from the scroll view and add it to the view controller view.
You can see it in action here
Later edit:
To actually see what I've changed you can check the file differences in Git. Basically I moved your titleViews (titleView1, titleView2, etc) from the scrollView to the view controller's view (so basically I've replaced all the lines that were like this:
[self.scrollView addSubView:self.titleView1]
to something like this:
[self.view addSubView:self.titleView1]
After that I've also took out the keyframe animations that were keeping your title views in place since they were not moving with the scrollview anymore. Practically I've deleted all the lines that were adding a frame animation to your titleviews from each configurePageXAnimation.
2nd question answer:
Say your screenshot view is called screenshotView. You can go ahead and create it like this:
UIImageView *screenshotView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"ScreenshotImage"]];
[self.view addSubview:screenshotView];
self.screenshotView = screenshotView;
[self.screenshotView setCenter:CGPointMake(self.view.center.x + self.view.bounds.size.width, <#yourDesiredY#>)];
And animate it like this:
//screenshotView frame animation
IFTTTFrameAnimation *screenshotViewFrameAnimation = [IFTTTFrameAnimation new];
screenshotViewFrameAnimation.view = self.screenshotView;
[self.animator screenshotViewFrameAnimation];
[screenshotViewFrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(1) andFrame:self.screenshotView.frame]];
[screenshotViewFrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(2) andFrame:CGRectOffset(self.screenshotView.frame, -self.scrollView.bounds.size.width, 0.0)]];
[screenshotViewFrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(3) andFrame:CGRectOffset(self.screenshotView.frame, -self.scrollView.bounds.size.width, 0.0)]];
[screenshotViewFrameAnimation addKeyFrame:[[IFTTTAnimationKeyFrame alloc] initWithTime:timeForPage(4) andFrame:CGRectOffset(self.screenshotView.frame, -self.scrollView.bounds.size.width * 2, 0.0)]];

Custom navbar sizing from iphone 5 to iphone 6

I have a custom tab bar that was optimized for the iphone 5.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
[self.view addSubview:myBar];
When it on the iphone 6, part of it is cut off of course because it only goes to 320 pixels.
How do i fix this? Is there a way to check which iphone its being ran on, and then run the pixel specified code? I plan on putting a background image on this navbar later so it must be centered.
In general it is a bad idea to hard code dimensions like this. This will break if you rotate, or if viewed on a screen with a different size than the original iPhone screen.
Many of these controls have a default size that you can use to your advantage. Instead of handing it a frame, consider just modifying the frame it gives you:
UINavigationBar *myBar = [[UINavigationBar alloc] init];
CGRect navBarFrame = myBar.frame;
navBarFrame.size.height // returns the right size for the current OS
navBarFrame.size.width = self.view.frame.size.width;
myBar.frame = navBarFrame;
This type of defensive coding is helpful in keeping your app laid out properly under many conditions, including when you embed this control into a parent view controller, or viewed on tomorrows larger-screened iOS devices.
All this said, are you sure you don't want a UIToolbar? Typically you don't ever create your own UINavigationBar, as that class is just used in UINavigationController for you.
UINavigationBar *myBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
[self.view addSubview:myBar];
may be this help you.

UIPopover equal screen width

I need to make popover size Equal device screen width, is it possible? I try such code:
ShareViewController *shareVC = [[ShareViewController alloc] init];
sharePopover = [[UIPopoverController alloc] initWithContentViewController:shareVC];
sharePopover.popoverContentSize = shareVC.view.frame.size; // width there is 1024 i'm sure
sharePopover presentPopoverFromRect:CGRectMake(sender.frame.origin.x, sender.frame.origin.y + 10, sender.frame.size.width, sender.frame.size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
also i tried to set width in popoverContentSize by number like 1024, or bigger, but no effect, i have some spaces in left and right, how can i fix it?
Here screenshot of problem:
http://uaimage.com/image/c54d471d
From Apple's UIPopoverController documentation, regarding the 'popoverLayoutMargins' property (can be found here: UIPopoverController documentation:
The margins that define the portion of the screen in which
it is permissible to display the popover....
...The edge inset values are measured in points from the edges of the screen,
relative to the current device orientation...
...The default edge insets are 10 points along each edge.
Try adding the following and see if it helps:
sharePopover.popoverLayoutMargins = UIEdgeInsetsZero;

How do I change the position of this element on the ViewController programatically?

I have this code in my ViewController.m but there is no Strobyboard/XIB file for it which is fine but on the screen the element comes up in the centre automatically. How Do I add a custom position to it?
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:_bgImage];
[self addSubview:bgImageView];
As far as I'm aware I should be able to add CGRectMake code somewhere but I can't figure it out.
Any suggestions?
bgImageView.frame =CGRectMake(x,y,width,height);
If you want to maintain the previous values:
bgImageView.frame =CGRectMake(x,y, bgImageView.frame.sizewidth, bgImageView.frame.size.height);

IIViewDeckController with left always showing on iPad

I am using IIViewDeckController and I would like to always have the left side controller open and resize the center view so that the layout looks similar to UISplitViewController.
According to the docs:
It is possible to have the viewController always show a side
controller. You do this by setting the maxSize value to any (positive)
nonzero value. This will force the centerview to be always opened,
exposing a side controller permanently. This only works when you have
ONE sidecontroller specified (this means either a left side controller
or a right side controller), because this scenario does not make sense
if you would be able to slide the center view in both directions. When
you have 2 side controllers, this property is ignored.
I have done exactly what it says, but it will not always show the side controller:
PUCNews *news = [[PUCNews alloc] init];
UINavigationController *newsNav = [[UINavigationController alloc] initWithRootViewController:news];
[puc.cachedViewControllers setObject:newsNav forKey:#"news"];
PUCLeftNavigationViewController *leftNav = [[PUCLeftNavigationViewController alloc] init];
IIViewDeckController *deckController = [[IIViewDeckController alloc] initWithCenterViewController:newsNav leftViewController:leftNav];
deckController.openSlideAnimationDuration = 0.20f;
deckController.closeSlideAnimationDuration = 0.20;
deckController.centerhiddenInteractivity = IIViewDeckCenterHiddenNotUserInteractiveWithTapToClose;
deckController.elastic = NO;
if ([Utility isIpad]) {
//deckController.leftSize = 200;
deckController.maxSize = 500;
//deckController.sizeMode = IIViewDeckLedgeSizeMode;
[deckController toggleLeftViewAnimated:NO];
deckController.centerhiddenInteractivity = IIViewDeckCenterHiddenUserInteractive;
deckController.resizesCenterView = YES;
deckController.panningMode = IIViewDeckNoPanning;
}
This also is causing some very strange rotation issues.
How can I always have the left side controller open and resize my center view so that it fits within the rest of the screen?
I've used this,
self.leftController = leftController;
self.leftSize = 700;
[self openLeftViewAnimated:NO];
this works for me because I want a small space in the left size. Probably you need to play with the size afterwards, but this works!
Hope it helps you.
Cheers

Resources