SetFrame Method doesn't work in ios8 - ios

I am using table view with dynamic height.
-(void)ShowTblRoomType
{
// [self.tableView_roomType setTranslatesAutoresizingMaskIntoConstraints:YES];
[self.tableView_roomType setFrame:CGRectMake(self.tableView_roomType.frame.origin.x, self.tableView_roomType.frame.origin.y, self.tableView_roomType.frame.size.width, self.tableView_roomType.rowHeight*self.roomtypeDetails.count)];
self.tableView_roomType.hidden = NO;
//set shadow to uitableview........
self.tableView_roomType.layer.masksToBounds = NO;
self.tableView_roomType.layer.cornerRadius = 8; // if you like rounded corners
self.tableView_roomType.layer.shadowOffset = CGSizeMake(-15, 20);
self.tableView_roomType.layer.shadowRadius = 3;
self.tableView_roomType.layer.shadowOpacity = 0.5;
}
From here I am calling this method
- (IBAction)showRoomTypeDetails:(id)sender
{
if(self.tableView_roomType.hidden == NO){
self.tableView_roomType.hidden = YES;
}else
{
[self ShowTblRoomType];
}
// [self.view_reservation bringSubviewToFront:self.tableView_roomType];
}
it works on below ios 8 but dosn't work on ios8.
on ios8 it shows only one cell.
Appreciate for help

Related

CGFloat MinimumValue vs CurrentValue

I created a custom slider with a uiview class ... everything works fine but I just have a problem ...
in my view controller implements the Custom Slider class this way
Main ViewController
#pragma mark SMALL STATS
-(KPStatsSlider *)statsSlider {
if (!_statsSlider) {
_statsSlider = [[KPStatsSlider alloc] init];
_statsSlider.minimumValue = 18;
_statsSlider.maximumValue = 30;
_statsSlider.currentValue = 12;
_statsSlider.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.statsSlider];
[self.statsSlider.topAnchor constraintEqualToAnchor:self.view.topAnchor constant:115].active = YES;
[self.statsSlider.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:0].active = YES;
[self.statsSlider.heightAnchor constraintEqualToConstant:70].active = YES;
[self.statsSlider.leftAnchor constraintEqualToAnchor:self.view.centerXAnchor constant:0].active = YES;
}
return _statsSlider;
}
as you can see, I can assign the value:
Current /
Minimum /
Maximum
In my personalized UIView I implemented this feature to prevent the CurrentValue value being smaller than MinimumValue but I can not get it running can you help me with this?
Custom Slider UIView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
[self defaultValue];
[self setupStatsTitle];
[self trackLine];
if (self.currentValue <= self.minimumValue) {
self.currentValue = self.minimumValue;
}
}
return self;
}
Seems like you want
if (self.currentValue <= self.minimumValue) {
self.currentValue = self.minimumValue;
}
In the setter of currentValue. For example:
- (void)setCurrentValue:(CGFloat)currentValue {
_currentValue = currentValue;
if (_currentValue < self.minimumValue) {
_currentValue = self.minimumValue;
}
if (_currentValue > self.maximumValue) {
_currentValue = self.maximumValue
}
}
Your code currently only checks when the slider is initialized, but not if currentValue is set later.
In general, I prefer to access an instance variable directly if I’m in that instance variable’s setter/getter to avoid confusion and possible infinite recursion, but your code as written is okay.

UITableViewCell constraints scrolling bug with UITextView

I have a subclass of UITableViewCell and using Masonry to setup constraints depends on my cell style (enum). For example I have a right wrapper with some buttons and sometimes I want to use excluded path for my UITextView when width of my wrapper isn't equal zero. All works good only after I scroll down to this cell and scroll up and down again. On the first try I have
And after I scroll up and down I have
- (void)setCellType:(ReservationCellType)cellType
{
self->_cellType = cellType;
CGFloat rightButtonsWrapperWidth = 0;
CGFloat rightButtonsWrapperHeight = 0;
if (cellType == ReservationCellTypeSeating) {
if (self.reservationStatus == ReservationStatusArrived) {
rightButtonsWrapperWidth = 100.f;
rightButtonsWrapperHeight = 100.f;
} else {
rightButtonsWrapperWidth = 0;
rightButtonsWrapperHeight = 0;
}
}
[self.rightButtonsWrapper mas_remakeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(rightButtonsWrapperWidth);
make.height.mas_equalTo(rightButtonsWrapperHeight);
}];
if (cellType == ReservationCellTypeSeating) {
if (self.reservationStatus == ReservationStatusArrived) {
[self addRightButtonsWrapperExcludedPathWidth:rightButtonsWrapperWidth height:rightButtonsWrapperHeight];
}
}
}
The code of addRightButtonsWrapperExcludedPathWidth:height:
- (void)addRightButtonsWrapperExcludedPathWidth:(CGFloat)width height:(CGFloat)height
{
CGRect frame = CGRectMake(CGRectGetMinX(self.rightButtonsWrapper.frame), CGRectGetMinY(self.rightButtonsWrapper.frame), width, height);
CGRect rightWrapperExclusionRect = [self.noteTextView convertRect:frame fromView:self.wrapper];
UIBezierPath *rightWrapperExcludedPath = [UIBezierPath bezierPathWithRect:rightWrapperExclusionRect];
self.noteTextView.textContainer.exclusionPaths = #[rightWrapperExcludedPath];
[self.wrapper layoutIfNeeded];
}
In cellForRowAtIndexPath: I call [cell layoutIfNeeded]; Help me out, please. And the second question is - my calculations always wrong before I call reloadData. And after some scrolling I got a lot of layout problems. Please, help me.

Modify frame of the frontView in SWRevealViewController

Typically, if one is using SWRevealViewController, the front view fully covers the rear view, and the rear view is visible only if some action is performed (swipe, tap etc). My requirement is that the rear view should always be visible at least a little bit when the view loads and when the user swipes back. I tried modifying the frame of the frontView to achieve this, but I saw no effect whatsoever.
I put the frame update frame code in a method:
-(void)updateFrontViewControllerFrameWithPadding:(BOOL)bProvidePadding
{
if (!bProvidePadding) {
CGRect frontViewControllerFrame = self.frontViewController.view.bounds;
CGFloat xOrigin = self.view.bounds.origin.x;
CGFloat nWidth = self.view.bounds.size.width;
frontViewControllerFrame.origin.x = xOrigin;
frontViewControllerFrame.size.width = nWidth;
self.frontViewController.view.frame = frontViewControllerFrame;
_frontViewShadowColor = [UIColor blackColor];
[_contentView reloadShadow];
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 20.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 15.0f;
nPadding = _rearViewRevealWidthIphone;
}
CGRect revealViewBounds = self.view.bounds;
CGFloat frontViewXPos = revealViewBounds.origin.x + nPadding;
CGFloat frontViewWidth = revealViewBounds.size.width - nPadding;
CGRect frontViewFrame = self.frontViewController.view.frame;
frontViewFrame.origin.x = frontViewXPos;
frontViewFrame.size.width = frontViewWidth;
self.frontViewController.view.frame = frontViewFrame;
_frontViewShadowColor = [UIColor colorWithWhite:0.5
alpha:0.5];
[_contentView reloadShadow];
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
This method is called from the viewWillLayoutSubviews method, with providePadding argument as TRUE. This method also needs to be called from places in SWRevealViewController where pan and tap gestures have been handled.
This is how the view looks when swiped:
This is the solution to the frame resizing problem:
-(void)updateFrontViewControllerFrameWithPadding:(BOOL)bProvidePadding
{
if (!bProvidePadding) {
CGRect frontViewControllerFrame = self.frontViewController.view.bounds;
CGFloat xOrigin = self.view.bounds.origin.x;
CGFloat nWidth = self.view.bounds.size.width;
frontViewControllerFrame.origin.x = xOrigin;
frontViewControllerFrame.size.width = nWidth;
self.frontViewController.view.frame = frontViewControllerFrame;
_frontViewShadowColor = [UIColor blackColor];
[_contentView reloadShadow];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f].CGColor;
frontViewLayer.shadowOpacity = 0.0f;
frontViewLayer.shadowOffset = CGSizeMake(0.0f, 0.0f);
frontViewLayer.shadowRadius = 0.0f;
}
else {
CGFloat nPadding = 0.0f;
if ([IILUtility targetDevice] == UIUserInterfaceIdiomPad) {
_rearViewRevealWidthIpad = 60.0f;
nPadding = _rearViewRevealWidthIpad;
}
else {
_rearViewRevealWidthIphone = 35.0f;
nPadding = _rearViewRevealWidthIphone;
}
CGRect revealViewBounds = self.view.bounds;
CGFloat frontViewXPos = revealViewBounds.origin.x + nPadding;
CGFloat frontViewWidth = revealViewBounds.size.width - nPadding;
CGRect frontViewFrame = self.frontViewController.view.frame;
frontViewFrame.origin.x = frontViewXPos;
frontViewFrame.size.width = frontViewWidth;
self.frontViewController.view.frame = frontViewFrame;
[self rearViewDeploymentForLeftPosition];
_frontViewShadowColor = [UIColor colorWithWhite:0.8f
alpha:0.0f];
[_contentView reloadShadow];
//There is a catch here. The shadow for _frontView is different from that of self.frontViewController.view
//If we do not modify the shadow for self.frontViewController.view then it overlaps with
// the shadow of _frontView. This is generally not a problem in the case when the rear view is in focus and the
//front view is toggled to the right. But if we need the front view to be shifted slighlty to the right even when
//its position is FrontViewPositionLeft, it is important to manage the shadow of self.frontViewController.view
//otherwise the shadow takes up width equal to the padding we have provided.
CALayer *frontViewLayer = self.frontViewController.view.layer;
frontViewLayer.shadowColor = [UIColor blackColor].CGColor;
frontViewLayer.shadowOpacity = _frontViewShadowOpacity;
frontViewLayer.shadowOffset = _frontViewShadowOffset;
frontViewLayer.shadowRadius = _frontViewShadowRadius;
//reset rearViewRevealWidth
[self resetRearViewRevealWidth];
}
}
This also takes into account the shadow related problem mentioned above.
This method needs to be called from appropriate places, eg; when the view loads initially, when pan or tap gestures are performed etc.

Particle system looks different on iOS 6 and ios7

I have a couple of particle systems on my app that I checked originally on an iPad 3 with ios7. The particles looked and behaved like I expected them, but when I test on an iPad2 with ios6. The particles are displaced up and are smaller. I have a subclass for the particles. Here's the code for one of my particle systems. I was wandering if the CGREctMake is positioning the particle in a different area on a non retina display, but that doesn't happen when I position other things on the display.
Code to call the particles.
- (void)ShowSteamEffect
{
//Create view for Steam particle effect.
CGRect SteamFrame = CGRectMake(790, 380, 100, 100);
//Show Steam effect
ShowSteam = [[SteamEffect alloc]initWithFrame:SteamFrame];
ShowSteam.hidden = NO;
[self.view insertSubview:ShowSteam aboveSubview:imgComputerLights];
}
Steam subclass.
#import "SteamEffect.h"
#implementation SteamEffect
{
CAEmitterLayer* SteamEmitter;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
SteamEmitter = (CAEmitterLayer*) self.layer;
//SteamEmitter.emitterPosition= CGPointMake(0, 0);
//SteamEmitter.emitterSize = CGSizeMake(10,10);
CAEmitterCell* Steam = [CAEmitterCell emitterCell];
Steam.birthRate = 50;
Steam.spin = .6;
Steam.lifetime = 1.7;
Steam.alphaRange = 0.2;
Steam.alphaSpeed = 0.2;
Steam.contents = (id)[[UIImage imageNamed:#"Steam1.png"]CGImage];
Steam.velocity = 30;
Steam.velocityRange = 50;
Steam.emissionLongitude = -60;
Steam.emissionRange = M_1_PI;
Steam.scale = .2;
Steam.scaleSpeed = .5;
Steam.yAcceleration = -200;
SteamEmitter.renderMode = kCAEmitterLayerBackToFront;
SteamEmitter.emitterShape = kCAEmitterLayerCircle;
SteamEmitter.emitterCells = #[Steam];
}
return self;
}
-(void)didMoveToSuperview
{
[super didMoveToSuperview];
if (self.superview==nil) return;
[self performSelector:#selector(disableEmitterCell) withObject:nil afterDelay:0.5];
}
-(void)disableEmitterCell
{
[SteamEmitter setValue:#0 forKeyPath:#"birthRate"];
}
+ (Class) layerClass
{
//tell UIView to use the CAEmitterLayer root class
return [CAEmitterLayer class];
}
- (void) setEmitterPosition:(CGPoint)pos
{
SteamEmitter.emitterPosition = pos;
}
- (void) toggleOn:(bool)on
{
//SteamEmitter.birthRate = on? 300 : 0;
}

Animating custom view half way the screen with an image in it - abrupt animation

In one of my views I have a bottom bar. A tap on this view animates a temporary cart half way to the screen. Now, where there is no item in the temporary table I show a no data overlay which is nothing but a view with an empty cart image and text underneath it.
The issue is: when this table animates to expand and collapse, the no data overlay does not look good during animation. It appears that the image is also shrinking/expanding until the temporary table view stops animating.
So, I tried by playing with the alpha of the temporary table view while this animation happens so that it does not look that bad. But this is not helping either. There is an abrupt flash in the end.
Any suggestions?
self.temporaryTable.backgroundView = self.noDataOverlay;
[UIView animateWithDuration:0.5 animations:^{
self.temporaryTable.alpha = 0.5;
} completion:^(BOOL finished) {
self.temporaryTable.alpha = 1.0;
}];
Here is my code for drawing the image:
- (void)drawRect:(CGRect)iRect scalingImage:(BOOL)iShouldScale {
CGRect aRect = self.superview.bounds;
// Draw our image
CGRect anImageRect = iRect;
if (self.image) {
//scale the image based on the height
anImageRect = CGRectZero;
anImageRect.size.height = self.image.size.height;
anImageRect.size.width = self.image.size.width;
#ifdef ACINTERNAL
if (iShouldScale) {
anImageRect = [self aspectFittedRect:anImageRect max:aRect];
} else {
anImageRect.origin.x = (iRect.size.width/2) - (anImageRect.size.width/2);
anImageRect.origin.y = kTopMargin;
}
#else
anImageRect.origin.x = (iRect.size.width/2) - (anImageRect.size.width/2);
anImageRect.origin.y = kTopMargin;
#endif
if (self.shouldCenterImage)
anImageRect.origin.y = (iRect.size.height/2) - (anImageRect.size.height/2);
[self.image drawInRect:anImageRect];
} else {
anImageRect.origin.y = (iRect.size.height/6);
anImageRect.size.height = (iRect.size.height/6);
}
// Draw our title and message
if (self.title) {
CGFloat aTop = anImageRect.origin.y + anImageRect.size.height + kSpacer;
CGFloat aWidth = aRect.size.width;
UIColor *aColor = [UIColor colorWithRed:96/256.0 green:106/256.0 blue:122/256.0 alpha:1];
[aColor set];
CGRect aTextRect = CGRectMake(0, aTop, aWidth, kTitleHeight * 2);
UIFont *aTitleFont = [UIFont boldSystemFontOfSize:kTitleFontSize];
[self.title drawInRect:aTextRect withFont:aTitleFont lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];
if (self.subTitle) {
UIFont *aSubTitleFont = [UIFont systemFontOfSize:kSubTitleFontSize];
aTextRect = CGRectMake(0, aTop+kSpacer, aWidth, kTitleHeight);
[self.subTitle drawInRect:aTextRect withFont:aSubTitleFont lineBreakMode:NSLineBreakByClipping alignment:NSTextAlignmentCenter];
}
}
}
- (void)addToView:(UIView *)iView {
// setting a unique tag number here so that if the user has any other tag there should not be a conflict
UIView *aView = [iView viewWithTag:699];
if (aView) {
[aView removeFromSuperview];
}
self.tag = 699;
[iView addSubview:self];
}
- (void)removeView {
[super removeFromSuperview];
}
-(void)setViewFrame:(CGRect) iFrame {
CGRect aRect = self.frame;
aRect.size.width = iFrame.size.width;
aRect.size.height = iFrame.size.height;
self.frame = aRect;
[self setNeedsDisplay];
}
- (CGRect)aspectFittedRect:(CGRect)iRect max:(CGRect)iMaxRect {
float anOriginalAspectRatio = iRect.size.width / iRect.size.height;
float aMaxAspectRatio = iMaxRect.size.width / iMaxRect.size.height;
CGRect aNewRect = iMaxRect;
if (anOriginalAspectRatio > aMaxAspectRatio) { // scale by width
aNewRect.size.height = iMaxRect.size.width * iRect.size.height / iRect.size.width;
} else {
aNewRect.size.width = iMaxRect.size.height * iRect.size.width / iRect.size.height;
}
aNewRect.origin.y = (iMaxRect.size.height - aNewRect.size.height)/2.0;
aNewRect.origin.x = (iMaxRect.size.width - aNewRect.size.width)/2.0;
return CGRectIntegral(aNewRect);
}
One possibility here is to fix the original problem, namely the fact that the empty cart image is expanding/collapsing as the view animates. Without seeing your code it is difficult to solve this problem, but in my own code what I do is set the contentMode of the UIImageView to UIViewContentModeBottom. This causes the image to stay the same size even though the image view that contains it may grow and shrink as part of the animation.
You see a flash because you animate alpha up to 0.5 and then when animation completes you set it from 0.5 to 1.0. Just animate the alpha up to 1.0:
[UIView animateWithDuration:0.5
animations:^
{
self.temporaryTable.alpha = 1.0;
}];

Resources