App behaviour changes after disconnected from xcode - ios

I am developing a new release of my app and have come across a very frustrating issue. i have some code that repositions a view on the screen after rotation(see below code) When i run it in the simulator there are no issues, when i test on a physical device there is also no issue, until i disconnect from xCode. After disconnecting from Xcode the view no longer re locates correctly. If i reconnect to Xcode and run again it still won't work as it used to/expected. I added the logging you see in the code and now know that on first execution the heigh and with are logging correctly but after disconnect they are reversed. I have also installed an adhoc distribution to a two different devices and again on first execution everything works fine(no Xcode connection this time). But if i completely close the app (double tap home and wipe up) on the next execution we get exactly the same outcome as before with the view repositioning off the screen(presumably the NSlog values will again be reversed). I have searched high and low and can't find any solutions at all.
- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
NSLog(#"rotate");
int height = [UIScreen mainScreen].bounds.size.height;
int width = [UIScreen mainScreen].bounds.size.width;
NSLog(#"%#,%d",#"height: ",height);
NSLog(#"%#,%d",#"width: ",width);
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationIsPortrait(orientation)==YES){
if ([self.vcID.text isEqualToString:#"i4"]) {
self.addheightCont.constant = 50;
}else{
self.addheightCont.constant = 100.0;
}
}else if (UIDeviceOrientationIsLandscape(orientation)==YES){
if ([self.vcID.text isEqualToString:#"i5"]) {
self.addheightCont.constant = 32.0;
}else if ([self.vcID.text isEqualToString:#"i4"]) {
self.addheightCont.constant = 32.0;
}else{
self.addheightCont.constant = 50.0;
}
}
if (height==568) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 320, 568);
self.imageScroller.frame = CGRectMake(0, 0, 320, 568);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(160, 284)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(160, 284)];
}
}else if (height==480){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 320, 480);
self.imageScroller.frame = CGRectMake(0, 0, 320, 480);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(160, 240)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(160, 284)];
}
}else if ((height==320) && (width==568)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 568, 320);
self.imageScroller.frame = CGRectMake(0, 0, 568, 320);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(277, 160)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(284, 160)];
}
}else if ((height==320) && (width==480)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 480, 320);
self.imageScroller.frame = CGRectMake(0, 0, 480, 320);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(240, 160)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(284, 160)];
}
}else if ((height==375) && (width==667)){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 667, 375);
self.imageScroller.frame = CGRectMake(0, 0, 667, 375);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(333.5, 187.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 304)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 304)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(333.5, 115)];
}
}else if (height==667) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 375, 667);
self.imageScroller.frame = CGRectMake(0, 0, 375, 667);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(187.5, 333.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 445)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 445)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(187.5,115)];
}
}else if (height==736) {
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 414, 736);
self.imageScroller.frame = CGRectMake(0, 0, 414, 736);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(207, 333.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 514)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 514)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(207,115)];
}
}else if (height==414){
self.imageScroller.delegate = self;
self.imageScroller.zoomScale = 0.0;
[self.imageScroller setContentOffset:CGPointMake(0, 0) animated:YES];
self.LargeImage.frame = CGRectMake(0, 0, 736, 414);
self.imageScroller.frame = CGRectMake(0, 0, 736, 414);
self.imageScroller.minimumZoomScale = 1.0;
self.imageScroller.maximumZoomScale = 100.0;
if (self.CommentsView.alpha == 1.0) {
[self.CommentsView setCenter:CGPointMake(368, 187.5)];
[self.ShowCommentsButton setCenter:CGPointMake(24, 380)];
[self.LikeButtonbutton setCenter:CGPointMake(70.5, 380)];
}
if (self.editCommentView.alpha == 1.0) {
[self.editCommentView setCenter:CGPointMake(368, 115)];
}
}
}

After Fahim's suggestion i did some research on auto layout and as a result have managed to implement a fix using auto layout. I have set a constraint for the distance of the comment view from the top and sides of the top of the parent view and simply change the constant values using the code below to animate the view on and off the screen. As a result i no longer need any of the code in my question in the view rotation. Although i didn't find an answer to why the behaviour changes when the phone is disconnected from Xcode its no longer an issue with auto layout doing all the work.
To animate the view on screen i use:
[UIView animateWithDuration:0.5 animations:^{
self.CommentViewOffset.constant = 40;
[self.view layoutIfNeeded];
}];
And off the screen i use:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView animateWithDuration:0.5 animations:^{
if (UIDeviceOrientationIsPortrait(orientation)==YES){
self.CommentViewOffset.constant = 750.0;
self.editComentViewOffset.constant = 750;
[self.view layoutIfNeeded];
}else if (UIDeviceOrientationIsLandscape(orientation)==YES){
self.CommentViewOffset.constant = 440;
self.editComentViewOffset.constant = 440;
[self.view layoutIfNeeded];
}
Now i have no need to do anything in the deviceOrientationDidChangeNotification method as everything is handled with auto layout. I must say i have avoided auto layout completely until now and really wish i had taken the time to do the research earlier.

Related

ScrollView doesn't work on iPad but works on iPhone

I have a scrollview and it is full off buttons. this scrollview work iphone but not work on ipad
#define scrollViewSizeForiPad 1000
#define scrollViewSizeForiPhone 600
#define locationButtonSizeForiPhone 50
#define locationButtonSizeForiPad 30
i added buttons like this
lc_button.frame = CGRectMake(0, 0, buttonSize, buttonSize);
[_uiScrollForLocations addSubview:lc_button];
and some labels
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
buttonSize = buttonWidthHeightForiPad;
lc_label.font = [UIFont systemFontOfSize:14];
lc_label.frame = CGRectMake(3, 100, buttonSize, 20);
} else {
buttonSize = buttonWidthHeightForiPhone;
lc_label.font = [UIFont systemFontOfSize:9];
lc_label.frame = CGRectMake(8, 50, buttonSize, 10);
}
[_uiScrollForLocations addSubview:lc_label];
-(void) showLocations:(NSMutableArray *)lc_array {
[self hideAllLocations];
[self addButtonToView:lc_array whichView:_uiScrollForLocations type:#"Location"];
CGSize pagesScrollViewSize = _uiScrollForLocations.frame.size;
int viewHeight;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
viewHeight = buttonWidthHeightForiPad;
} else {
viewHeight = buttonWidthHeightForiPhone;
}
_uiScrollForLocations.contentSize = CGSizeMake(pagesScrollViewSize.width, viewHeight);}
It happen because contentSize <= _uiScrollForLocations.frame
Need set
_uiScrollForLocations.alwaysBounceVertical = YES
or
_uiScrollForLocations.alwaysBounceHorizontal = YES

Cropping image same as updated version of Instagram

I want to crop image in my application same as updated Instagram.
I have create one demo for it.
But i got 1 issue in this demo.
Issue is that, when i zoomIn image and then try to zoom out little bit that time UIImageview zooming out full. Please check demo u got my point which i try to explain
This is my demo link
https://drive.google.com/file/d/0Bw367uJS6w22OTNwTmdCNW5Ta3M/view?usp=sharing
you can this library if you want instagram like camera and imagepicker
https://github.com/ytakzk/Fusuma
In VPImageCropperViewController file You will find a method
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer you have to change in that code to work zoom out functionality.
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = self.showImgView;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
//pinchGestureRecognizer.scale = 1;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
NSLog(#"%f",pinchGestureRecognizer.scale);
// pinchGestureRecognizer.view.transform = CGAffineTransformScale(pinchGestureRecognizer.view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
// pinchGestureRecognizer.scale = 1;
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) {
NSLog(#"original image size%f",self.originalImage.size.width);
NSLog(#"latestFrame image size%f",self.latestFrame.size.width);
// NSLog(#"original image size%f",self.originalImage.size.width);
// NSLog(#"original image size%f",self.originalImage.size.width);
/* if(pinchGestureRecognizer.scale <= 1.0)
{
// small
CGRect newFrame = self.showImgView.frame;
UIImage *img=[self imageWithImage:self.originalImage scaledToSize:self.cropFrame.size];
newFrame = [self handleScaleOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleBorderOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
}];
}*/
/* if(pinchGestureRecognizer.scale > 1.0)
{*/
// big
CGRect newFrame = self.showImgView.frame;
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
}];
//}
}
}
May be it will help you.
Do changes in VPImageCropperViewController.m file
// pinch gesture handler
- (void) pinchView:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
UIView *view = self.showImgView;
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan || pinchGestureRecognizer.state == UIGestureRecognizerStateChanged) {
view.transform = CGAffineTransformScale(view.transform, pinchGestureRecognizer.scale, pinchGestureRecognizer.scale);
self.showImgView.contentMode=UIViewContentModeRedraw;
self.editedImage=self.showImgView.image;
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded) {
if(view.frame.size.width <= self.cropFrame.size.width && view.frame.size.height <= self.cropFrame.size.height)
{
// Zoom out
CGRect newFrame = self.showImgView.frame;
UIImage *img=[self imageWithImage:self.originalImage scaledToSize:self.cropFrame.size];
newFrame = [self handleScaleOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleBorderOverflow:CGRectMake(0, 0, img.size.width, img.size.height)];
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
self.showImgView.contentMode=UIViewContentModeScaleAspectFit;
CGRect cropRect = AVMakeRectWithAspectRatioInsideRect(self.showImgView.image.size, self.showImgView.frame);
NSLog(#"frame %f %f ",cropRect.size.width,cropRect.size.height);
}];
}
else
{
// Zoom In
CGRect newFrame = self.showImgView.frame;
newFrame = [self handleScaleOverflow:newFrame];
newFrame = [self handleBorderOverflow:newFrame];
[UIView animateWithDuration:BOUNDCE_DURATION animations:^{
self.showImgView.frame = newFrame;
self.latestFrame = newFrame;
}];
}
}
}

How to simulate paper fold while inserting and deleting rows in a UITableView

So I am trying to simulate an origami type paper fold while adding and deleting cells much like the peek Calendar app:
I have gotten pretty close to this functionality by subclassing the UITableView and overriding the insertRowsAtIndexPaths:withRowAnimation: and the deleteRowsAtIndexPaths:withRowAnimation:
However right now I just cant seem to get the animation looking right. Below is my current code - I would just like to help getting over this last hurdle (or maybe there is a completely different approach such as adding a tableview to a tableviewcell).
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths
withRowAnimation:(UITableViewRowAnimation)animation
{
[super insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
float duration = .30;
int i = 0;
for (NSIndexPath *indexPath in indexPaths) {
__block UITableViewCell *cell = [super cellForRowAtIndexPath:indexPath];
if (cell) { // If indexPath isn't visible we'll get nil here
//even cells flip up while odd cells flip down
if(i % 2 ==0){
cell.layer.anchorPoint = CGPointMake(.5, 0);
//start row off by rotating 90 degrees
__block CATransform3D t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.bounds.size.height/2, 0);
t = CATransform3DRotate(t, hn_radians(90), 1, 0, 0);
t.m34 = -1.0/(cell.layer.bounds.size.height * 4.6666667);
cell.layer.transform = t;
//flip up
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.bounds.size.height/2, 0);
cell.layer.transform = t;
NSLog(#"");
} completion:^(BOOL finished) {
cell.layer.transform = CATransform3DIdentity;
cell.layer.anchorPoint = CGPointMake(.5, .5);
}];
}
else{
cell.contentView.layer.anchorPoint = CGPointMake(.5, 1);
//start row off by rotating 90 degrees
__block CATransform3D t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, -cell.contentView.bounds.size.height * 0.5f, 0);
t = CATransform3DRotate(t, hn_radians(-90), 1, 0, 0);
t.m34 = -1/500.f;
cell.contentView.layer.transform = t;
//flip down
[UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
t = CATransform3DIdentity;
t = CATransform3DTranslate(t, 0, cell.contentView.bounds.size.height * 0.5f, 0);
cell.contentView.layer.transform = t;
} completion:^(BOOL finished) {
//reset anchor and transform
cell.contentView.layer.transform = CATransform3DIdentity;
cell.contentView.layer.anchorPoint = CGPointMake(.5, .5);
}];
}
i++;
}
}
}
In the UITableViewCell.h file write this :
#property (nonatomic, assign) CGFloat finishedHeight;
#property (nonatomic, strong) UIView *transformable1HalfView;
#property (nonatomic, strong) UIView *transformable2HalfView;
In the UITableViewCell .m file write this :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization
CATransform3D transform = CATransform3DIdentity;
transform.m34 = -1/500.f;
[self.contentView.layer setSublayerTransform:transform];
self.transformable1HalfView = [[UIView alloc] initWithFrame:self.contentView.bounds];
[self.transformable1HalfView.layer setAnchorPoint:CGPointMake(0.5, 0.0)];
[self.transformable1HalfView setClipsToBounds:YES];
[self.contentView addSubview:self.transformable1HalfView];
self.transformable2HalfView = [[UIView alloc] initWithFrame:self.contentView.bounds];
[self.transformable2HalfView.layer setAnchorPoint:CGPointMake(0.5, 1.0)];
[self.transformable2HalfView setClipsToBounds:YES];
[self.contentView addSubview:self.transformable2HalfView];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.textLabel.autoresizingMask = UIViewAutoresizingNone;
self.textLabel.backgroundColor = [UIColor clearColor];
self.detailTextLabel.autoresizingMask = UIViewAutoresizingNone;
self.detailTextLabel.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGFloat fraction = (self.frame.size.height / self.finishedHeight);
fraction = MAX(MIN(1, fraction), 0);
CGFloat angle = (M_PI / 2) - asinf(fraction);
CATransform3D transform = CATransform3DMakeRotation(angle, -1, 0, 0);
[self.transformable1HalfView.layer setTransform:transform];
[self.transformable2HalfView.layer setTransform:CATransform3DMakeRotation(angle, 1, 0, 0)];
CGSize contentViewSize = self.contentView.frame.size;
CGFloat contentViewMidY = contentViewSize.height / 2;
CGFloat labelHeight = self.finishedHeight / 2;
// OPTIONAL: Always accomodate 1 px to the top label to ensure two labels
// won't display one px gap in between sometimes for certain angles
self.transformable1HalfView.frame = CGRectMake(0, contentViewMidY - (labelHeight * fraction),
contentViewSize.width, labelHeight + 1);
self.transformable2HalfView.frame = CGRectMake(0, contentViewMidY - (labelHeight * (1 - fraction)),
contentViewSize.width, labelHeight);
if ([self.textLabel.text length]) {
self.detailTextLabel.text = self.textLabel.text;
self.detailTextLabel.font = self.textLabel.font;
self.detailTextLabel.textColor = self.textLabel.textColor;
self.detailTextLabel.textAlignment = self.textLabel.textAlignment;
self.detailTextLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.shadowColor = self.textLabel.shadowColor;
self.detailTextLabel.shadowOffset = self.textLabel.shadowOffset;
}
self.textLabel.frame = CGRectMake(10.0, 0.0, contentViewSize.width - 20.0, self.finishedHeight);
self.detailTextLabel.frame = CGRectMake(10.0, -self.finishedHeight / 2, contentViewSize.width - 20.0, self.finishedHeight);
}
Reference : https://github.com/jamztang/JTGestureBasedTableViewDemo
Cheers.

Animating UIScrollView with paging

I am having a scrollView having 2 subviews per screen and thus 10 subviews.Paging is disabled right now. Now i want whenever I swipe up the subviews inside scrollviews, they should fill the entire screen and after then, normal scrolling is applicable having 10 views each on one screen with paging enabled.Any help??
const NSUInteger kNumViews= 10;
const CGFloat vScrollObjWidth = 160.0;
const CGFloat vScrollObjHeight = 280.0;
- (void)layoutScrollViews
{
UIView *view = nil;
NSArray *subviews = [scrollView2 subviews];
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (vScrollObjWidth);
}
}
[scrollView2 setContentSize:CGSizeMake((kNumViews+1) * vScrollObjWidth, scrollView2.bounds.size.height)];
}
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
scrollView2.delegate = self;
[scrollView2 setBackgroundColor:[UIColor blackColor]];
scrollView2.scrollEnabled = YES;
for (i = 1; i <= kNumViews; i++)
{
NSString *imageName = [NSString stringWithFormat:#"imageV%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView sizeToFit];
imageView.layer.borderColor = [UIColor grayColor].CGColor;
imageView.layer.borderWidth = 1.5f;
CGRect rect = imageView.frame;
rect.size.height = vScrollObjHeight;
rect.size.width = vScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
imageView.userInteractionEnabled = YES;
[scrollView2 addSubview:imageView];
}
[self layoutScrollViews];
self.swipeRecognizerUp = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(scaleMove:)];
[self.swipeRecognizerUp setDelegate:self];
[scrollView2 addGestureRecognizer:self.swipeRecognizerUp];
self.swipeRecognizerDown = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(scaleDown:)];
[self.swipeRecognizerDown setDelegate:self];
[scrollView2 addGestureRecognizer:self.swipeRecognizerDown];
self.swipeRecognizerDown.enabled = NO;
}
-(void)scaleMove:(id)sender {
[[[(UIPanGestureRecognizer*)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[sender view]];
CGPoint velocity = [sender velocityInView:self.view];
if(abs(velocity.y) - abs(velocity.x) > 500 && velocity.y < 0){
CGAffineTransform scale = CGAffineTransformMakeScale(1, 0.82);
CGAffineTransform translate = CGAffineTransformMakeTranslation(0,254);
[sender view].transform = CGAffineTransformConcat(translate, scale);
[UIView animateWithDuration:0.5
animations:^(){
CGAffineTransform scale = CGAffineTransformMakeScale(2, 1.64);
CGAffineTransform translate = CGAffineTransformMakeTranslation(0,-254);
[sender view].transform = CGAffineTransformConcat(translate, scale);
}
completion:nil];
scrollView2.pagingEnabled = YES;
self.swipeRecognizerDown.enabled = YES;
self.swipeRecognizerUp.enabled = NO;
}
}
-(void)scaleDown:(id)sender {
[[[(UIPanGestureRecognizer*)sender view] layer] removeAllAnimations];
[self.view bringSubviewToFront:[sender view]];
CGPoint velocity = [sender velocityInView:self.view];
if(abs(velocity.y) - abs(velocity.x) > 500 && velocity.y > 0){
[sender view].transform = CGAffineTransformMakeScale(2, 1.64);
[UIView animateWithDuration:0.5
animations:^(){
[sender view].transform = CGAffineTransformMakeScale(1.0, 0.82);
}
completion:nil];
scrollView2.pagingEnabled = NO;
self.swipeRecognizerUp.enabled = YES;
self.swipeRecognizerDown.enabled = NO;
}
}

Objective-C - Animate button with blocks?

I have a UIScrollView and a UIButton. I am using blocks to animate them however the button won't animate while the UIScrollView does? Can you not animate a button like this?
Any help would be appreciated greatly!
- (void)viewDidLoad
{
[super viewDidLoad];
draw1 = 0;
scrollView.frame = CGRectMake(0, -200, 768, 200);
[scrollView setContentSize:CGSizeMake(768, 200)];
openMenu.frame = CGRectMake(680, 100, 55, 55);
}
- (IBAction)openMenu:(id)sender {
if (draw1 == 0) {
draw1 = 1;
CGRect optionsDrawer = scrollView.frame;
CGRect optionsButton = openMenu.frame;
optionsDrawer.origin.y += 200;
[UIView animateWithDuration:0.5
animations:^{
scrollView.frame = optionsDrawer;
openMenu.frame = optionsButton;
}];
} else {
draw1 = 0;
CGRect optionsDrawer = scrollView.frame;
CGRect optionsButton = openMenu.frame;
optionsDrawer.origin.y -= 200;
[UIView animateWithDuration:0.5
animations:^{
scrollView.frame = optionsDrawer;
openMenu.frame = optionsButton;
}];
}
}
Ah! I forgot to add the origin to the button as well! Oops!
Fixed with adding to each:
optionsButton.origin.y += 200;

Resources