這是在ModalViewController
後......被打印一遍又一遍。transitionWithView被使用<code>StoryBoard</code>和<code>ARC</code></p> <p>當我解僱我看到這一行的看法... <code>NSLog(@"%d %@",[imgArray count],fileName);</code>一再呼籲的ViewController被駁回
當視圖被解散時,我該如何殺掉函數transitionWithView/animateWithDuration
?
缺少一些相當重要的東西!
.H
#import <UIKit/UIKit.h>
@interface InfoVC : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *imageview;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@end
的.m
#import "InfoVC.h"
#import <QuartzCore/QuartzCore.h>
@interface InfoVC()
@end
@implementation InfoVC {
int randomInt;
NSArray *imgs;
NSMutableArray *imgArray;
NSTimer *myTimer;
NSTimer *myTimer2;
NSString *currentImg;
}
- (void)viewDidLoad
{
[super viewDidLoad];
imgs = [NSArray arrayWithObjects:
@"01.jpg",
@"02.jpg",
@"03.jpg",
nil];
imgArray = [imgs mutableCopy];
[self initialImage];
}
- (void)initialImage
{
_imageview.contentMode = UIViewContentModeLeft;
int rnd = [imgArray count];
randomInt = (arc4random()%rnd);
currentImg = [imgArray objectAtIndex:randomInt];
UIImage *image = [UIImage imageNamed:currentImg];
[_imageview setImage:image];
_imageview.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
_scrollview.contentSize = image.size;
_scrollview.contentOffset = CGPointMake(-150.0, 0.0);
[imgArray removeObjectAtIndex: randomInt];
[self animate];
}
- (void)randomImage
{
if ([imgArray count]==0) {
imgArray = [imgs mutableCopy];
}
int rnd = [imgArray count];
randomInt = (arc4random()%rnd);
NSString *fileName = [imgArray objectAtIndex:randomInt];
NSLog(@"%d %@",[imgArray count],fileName);
[imgArray removeObjectAtIndex: randomInt];
UIImage * toImage = [UIImage imageNamed:fileName];
void (^completion)(void) = ^{
[self animate];
};
[UIView transitionWithView:self.view
duration:1.75f
options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction
animations:^
{
_imageview.image = toImage;
}
completion:^(BOOL finished)
{
completion();
}
];
}
- (void)animate{
CGPoint offset = _scrollview.contentOffset;
float flt = 150.0;
if (_scrollview.contentOffset.x == flt)
{
offset.x = 0.0 ;
}
else
{
offset.x = flt ;
}
void (^completion2)(void) = ^{
[self randomImage];
};
[UIView animateWithDuration:5.0 delay:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseIn
animations:^{
_scrollview.contentOffset = offset;
}completion:^(BOOL completed){
completion2();
}
];
}
- (void)viewDidUnload
{
[super viewDidUnload];
[_scrollview.layer removeAllAnimations];
[_imageview.layer removeAllAnimations];
}
- (IBAction)dismissInfo:(id)sender
{
[_scrollview.layer removeAllAnimations];
[_imageview.layer removeAllAnimations];
[self dismissModalViewControllerAnimated:YES];
}
通過調用其他函數和其他函數調用相同的被調用的函數來生成無限循環.....我的建議您需要更改模型 – Spynet
是的我想要一個無限循環,它只是保持突出。自發布我嵌套了兩個塊,但問題是,一旦控制器被刪除,隨機圖像塊快速連續調用 - 方式比當控制器存在時更快 – JulianB