I implement the grid view cell size with this method:
- (CGSize)cellSize {
return _gridMode ? CGSizeMake(100, 100) : CGSizeMake(320, 345);
}
And check
_gridMode
for determining which cell to display (either a thumbnail or a full-screen cell).
The full screen cell is supposed to be 320x345.
It draws no subviews wider than 320px.
When I draw the full screen cell, I cannot scroll and when I switch back to grid mode, I see nothing (black screen).
When I set cellSize to 310x345 instead of 320x345, it works -- except my full screen subvies get offset by a few pixels horizontally.
What should I do to display full-screen width AQGridViewCells?
Related
I have a UIScrollView which resets its contentOffset anytime the view is tapped.
This is demonstrated here: https://gyazo.com/c8fb5c0fa5b6d53acf45c809dcb5b251
What I've tried:
Disabling keyboard dismissal
Checking for isDragging on scrollViewDidScroll and resetting the content offset if it was false. This resulted in jumpy behavior.
Reading this question, it did not help.
You can test it yourself here: https://github.com/willbishop/scrollviewwizardry
Any ideas?
You could turn off paging if that is not the intended result you're looking for:
scrollView.isPagingEnabled = false
If paging is something you're looking to use:
Paging is meant for snapping between multiple views in a ScrollView, usually where each subview is the size of the ScrollView's bounds. Since you've enabled paging with vertical scrolling, and your ScrollView content height is less than two "pages" height, unexpected results from paging are occurring.
For your situation, if you set each view in your ScrollView equal to the ScrollView's height, and your ScrollView contentSize height is equal to its subview's combined height, then paging works properly and the content offset doesn't reset when tapped:
scrollView.frame.size.height = view.frame.height
subView1.frame.size.height = view.frame.height
subView2.frame.size.height = view.frame.height
scrollView.contentSize.height = subView1.frame.height + subView2.frame.height
It will snap between showing your two views when the ScrollView stops being scrolled. You could also have your "peekAmount" where the second view shows at the bottom while still scrolled to the top "page", as long as the height of your ScrollView contentSize is equal to twice the ScrollView bounds height (i.e. two pages).
I have a scroll view that has a content view inside of it.
The scroll view has constraints to the top, bottom, leading and trailing content view and top, leading, trialing superview with the bottom space to the bottom layout.
I change the Content View width on rotation:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
_contentWidth.constant = 480;
}else{
//iPhone Portrait
_contentWidth.constant = 320;
}
}
When I run the app and rotate to landscape, the width of the Content View changes and everything looks good, but the scroll view only allows scrolling on the left half of the screen (the whole view scrolls but your finger must be on the left side of screen to scroll). The Scroll View frame = (0 0; 320 431);.
If I go to another tab on my tab bar and return to this View the frame = (0 0; 480 320); what it is supposed to be and everything works/looks fine.
Any ideas what I need to do to get this by not selecting another tab and coming back?
EDIT
I made a subclass of Content View called ContentViewSubclass and put the following method in it:
-(CGSize)intrinsicContentSize{
CGSize size;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
size.height = 1000;
size.width = 480;
return size;
}else{
//iPhone Portrait
size.height = 1000;
size.width = 320;
return size;
}
}
Then on my ViewController.m I updated to the following code:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[_contentView invalidateIntrinsicContentSize];
[_contentView intrinsicContentSize];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{ _contentWidth.constant = 480;
_contentHeight.constant = 1000;
}else{
//iPhone Portrait
_contentWidth.constant = 320;
_contentHeight.constant = 1000;
}
}
When I log the sizes I get
Landscape:
ContentViewSubclass frame is (0 0, 480 1000)
UIScrollView frame is (0 20, 480 251)
contentView intrinsic size is {480, 1000}
Portrait:
ContentViewSubclass frame is (0 0; 320 1000)
UIScrollView frame is (0 20, 320 411)
contentView intrinsic size is {320, 1000}
Everything is in a Tab Bar View Controller and here is what it is set up like:
View
ScrollView
ContentView
Labels (many)
Textfields (many)
TableView (2)
CollectionViewSubcless (1)
I deleted the table views and Collection View in case they were causing problems and that didn't help.
Same issue. I get the correct layout on everything and it all scrolls, but you have be touching the left half of screen in landscape to scroll it. If I go to another tab view and return to this one it works correct. The scroll view then shows UIScrollView frame is (0 20, 480 300).
You're using the "Pure AutoLayout Approach" described here by Apple in a Technical Note: https://developer.apple.com/library/ios/technotes/tn2154/_index.html
The "Pure AutoLayout Approach" works in Apple's sample code because an image view has an intrinsic content size; your content view, on the other hand, does not.
If you don't want to switch to the "Mixed Approach", then your content view will have to have an intrinsic content size. You do that by creating a UIView subclass and overriding the intrinsicContentSize method. In the willRotateToInterface… method, send invalidateIntrinsicContentSize to your content view.
I struggled with a similar situation. In my case it was the rightmost section of the landscape screen-width which is "added" to the portrait screen-width when rotated to landscape (i.e. for all values of x where: w-h < x <= w). Buttons and such which were constrained to move into that area were there, but were unresponsive. If that sounds the same as what you're seeing, then this simple solution might help. It fixed it for me.
I have UITableview which has custom cells with UIImageViews. In the UITableview I am increasing the height of the cell using didSelectRowAtIndexPath method. Also i am adding method to increase cell height and revert to normal height.
When i tap on the cell the height is increasing , when i tap on the cell again (in order to make the tableviewcell return to default height) while in transition the image which is on tableviewcell is stays like its shown below and goes back to default height ..(i dont know how the image is being displayed while in transition)
-(void) zoomOutProperties
{
fruitImage.frame=CGRectMake(0.0, 46.0, 320.0, 83.5);
backgroundCellImage.frame=CGRectMake(0.0, 0.0, 320.0,129.5);
customCellView.frame=CGRectMake(0.0, 0.0, 320.0, 129.5); // UIView
}
Please note ::
[UIImage imageNamed:#""] caches the image. Instead use: [UIImage imageWithContentsOfFile:#""]
To make the image equal to the UIImageView size, you should use:
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
Refer: https://stackoverflow.com/a/9945160/667586
Your numbers for the frames don't add up very well. For instance, in zoomInProperties, you set fruitImage to have origin.y at 73.0, but its height is 82.5 (fractional pixels?) so it will end at 155.5, which is below the bottom of the customCellView which is 135.6. If the outer cell UIView is not set to clip, then the image will draw partly into the next cell.
Also, by setting the inner frames before setting the outer customCellView, you could have 2 changes to the sizes if they have autoResizeMask applied.
I have an Image and an ImageView, the ImageView occupies the whole screen and I want to resize the image to fit the ImageView. The ImageView is inside a ScrollView with only vertical scroll bar enabled, which means the Image should be resized with maximum width equal to that of the screen(ImageView), in the mean time keeping the ratio, not constrained on the resized height. The ImageView's height will fit with resized Image, if the height exceeds the height of the screen we can use the scroll bar to see it.
So I want suggestions on:
1) How I can resize an Image with a fixed width if the original width is less than the desired one, no resize is required. No constraint on height.
2) How I can make the ImageView fit the height of the Image automatically?
First, you can calculate the new image's height by yourself.
(if, image's size = (300,200), imageView's width = 320, the new image's height = 200*(320/300))
Then, from this thread The simplest way to resize an UIImage?
You can resize the Image with new width and height.
Total soultion:
UIImage* i= /* original image */;
UIImage* j =[self imageWithImage:i scaledToSize:newSize]; //new Image
[theImageView setImage:j];
(And this code also works fine with iOS 4.x)
-(void) keyboarddidhide:(NSNotification*)notif
{
if(!keyboardvisible)
{
return;
}
NSDictionary *info=[notif userInfo];
NSValue* avalue=[info objectForKey:UIKeyboardBoundsUserInfoKey];
CGSize keyboardSize=[avalue CGRectValue].size;
//Tag: Image Size as before
CGRect viewFrame=self.view.frame;
**viewFramesize.height+=keyboardSize.height;**
//Here I am just streaching the scrollView......
scrollView1.frame=viewframe; //Streaching the scroll view
keyboardvisible=yes;
//Tag: Image size increases....
keyboardvisible=false;
}
I am using XCode 4.
In my App I have a view page.
View
- Scroll View
- Text View
- Image View
-barButton
It is After the Notification that my image is streaching to full screen some how...
Whenevr my scroll view streches my image view stretches to the full screen.
Is there any property or method to fix the scrollview size or reset?
Your image view will stretch because you are stretching the ScrollView, if you do not want your scroll view to stretch
set the content size of the scroll view to zero.
I would suggest you to read