0

私のコードは UIImage を画面の下部にドロップします。しかし、同じコードをisMyUIViewControllerDelegateTriggeredに配置すると機能しません。これは同じスレですよね??

MyUIViewController.m

@interface MyUIViewController () <UIDynamicAnimatorDelegate>

@property (strong, nonatomic) UIDynamicAnimator *animator;
@property (strong, nonatomic) DropitBehavior *dropitBehavior;
@property (strong, nonatomic) IBOutlet UIView *jobLoadView;

@end

@synthesize someUIImage;

id refToSelf;  /* Tried this to have a ref to the UIView, but doesn't work. */
static DropitBehavior * dropit;

- (void)viewDidLoad
{
    refToSelf = self;
    dropit = [[DropitBehavior alloc] init];

    /* Placed inhere, this code works!
    DropitBehavior * dropit = [refToSelf dropitBehavior];
    [dropit addItem:someUIImage]; */

    startupManager = [[StartupManager alloc] init];
    [startupManager setDelegate:refToSelf];
    [startupManager start];
}

- (DropitBehavior *)dropitBehavior
{
    if (!_dropitBehavior) {
        _dropitBehavior = [[DropitBehavior alloc] init];
        [self.animator addBehavior:_dropitBehavior];
    }
    return _dropitBehavior;
}

- (UIDynamicAnimator *)animator
{
    if (!_animator) {
        _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.jobLoadView];
        _animator.delegate = self;
    }
    return _animator;
}


-(void)isStartupManagerDelegateTriggered:(NSString *) errorcode {        
    /* The startup manager code triggers 5 time, so I can make a loading effect. */

    /* Doesn't work when I place the code inhere. */
    dropit = [refToSelf dropitBehavior];

    if ([dropit isKindOfClass:[DropitBehavior class]]) {
       NSLog(@"is kind of class drop it ");
       [dropit addItem:someUIImage];
    }
}

DropitBehavior.m

@interface DropitBehavior()
@property (strong, nonatomic) UIGravityBehavior *gravity;
@property (strong, nonatomic) UICollisionBehavior *collider;
@end

@implementation DropitBehavior

/* Singleton */
static DropitBehavior *sharedSingleton;

+ (void)initialize {
    static BOOL initialized = NO;
    if(!initialized)
    {
        initialized = YES;
        sharedSingleton = [[DropitBehavior alloc] init];
    }
}

- (UIGravityBehavior *)gravity
{
    if (!_gravity) {
        _gravity = [[UIGravityBehavior alloc] init];
        _gravity.magnitude = 0.9;
    }
    return _gravity;
}

- (UICollisionBehavior *)collider
{
    if (!_collider) {
        _collider = [[UICollisionBehavior alloc] init];
        _collider.translatesReferenceBoundsIntoBoundary = YES;
    }
    return _collider;
}

- (void)addItem:(id <UIDynamicItem>)item
{
    [self.gravity addItem:item];
    [self.collider addItem:item];
}

- (instancetype)init
{
    self = [super init];
    [self addChildBehavior:self.gravity];
    [self addChildBehavior:self.collider];
    return self;
}

@end

StartupManager.m

@implementation StartupManager

JSONParser * jsonParser;
HTTPConnection * httpConnection;
static StartupManager *sharedSingleton;
@synthesize delegate;

+ (void)initialize {

    static BOOL initialized = NO;
    if(!initialized) {
        initialized = YES;
        sharedSingleton = [[StartupManager alloc] init];
        jsonParser = [[JSONParser alloc] init];
        httpConnection = [[HTTPConnection alloc] init];
    }
}

- (void) doingSomeStuff {

        [httpConnection setDelegate:self];
        [httpConnection postRequestToSomeServer:@"some.instance.inthe.cloud";
}

-(void)isHTTPConnectionDelegateTriggered:(NSData *)jsonPost {

    [jsonParser setDelegate:self];
    [jsonParser parseJSON:jsonPost];
}

-(void)isJSONParserDelegateTriggered:(NSString *) message {

    */ this gets called periodically and that has to do a loading screen animation. /*
    [delegate isStartupManagerDelegateTriggered:message];
}

StartupManager.h

@class StartupManager;

@protocol StartupManagerDelegate

@required
    -(void)isStartupManagerDelegateTriggered:(NSString *) errorcode;
@end

@interface StartupManager : NSObject <JSONParserDelegate, HTTPConnectionDelegate>

@property (nonatomic, assign) id<StartupManagerDelegate>  delegate;

- (void) doingSomeStuff;

私を正しい方向に向けることができる人はいますか?そうでなければ、おじいさんに頼まなければなりません。

4

1 に答える 1

0

UIDynamicAnimatorDelegate プロトコルを誤解している可能性があると思います。アニメーションを開始するのではなく、アニメーションの状態が変化したことを知らせるだけです。

したがって、通常、デリゲート メソッドからアニメーションを開始することはありません。いずれにせよ、投稿したコードはデリゲート メソッドを実装していません。投稿されたコードでアニメーションを開始する唯一の方法は、明示的に呼び出すことですisMyUIViewControllerDelegateTriggered

いつ開始しますか? viewDidLoad早すぎます。 viewDidAppear通常、これは、ユーザーに表示されると予想される最も早い妥当な時間です。

于 2014-05-10T20:22:01.470 に答える