2012-12-04 13 views
6

मैं एक UIActionSheet इस तरह दिखा रही है:UIActionSheet showFromRect autorotation

-(void)accessoryPressed:(id)sender{ 
    //Omitted unnecessary objects 

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:titleString delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:@"Upload", nil]; 
    //actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; 
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
    actionSheet.tag = ((UIButton*)sender).tag; 
    [actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES]; 
} 

sender वस्तु एक UIButton एक UITableViewCell के गौण दृश्य में एम्बेडेड है कहाँ।

समस्या यह है कि जब आईपैड घुमाया जाता है तो एक्शनशीट आकार बदल नहीं रहा है (मुझे उम्मीद है कि यह वास्तव में रिज्यूज करने की उम्मीद नहीं है, लेकिन मैं इसे सही एक्स, वाई में होना चाहता हूं) मैंने ऑटोरेसाइजिंग मास्क को फ्लेक्सिबल लेफ्ट और फ्लेक्सिबलटॉप पर सेट करने की कोशिश की लेकिन यह बदल नहीं प्रतीत होता है।

क्या किसी को भी ऑटो-रोटेशन के बाद accessoryView पर इंगित करने के लिए कार्रवाईशीट प्राप्त करने के बारे में कोई जानकारी है?

यहाँ कि यह दिखता है: रोटेशन- Before Rotation

पहले

रोटेशन के बाद - enter image description here

उत्तर

7

यह एक शर्म की बात है UIKit ठीक से हमारे लिए इस संभाल नहीं करता है। अपने स्वयं के ऐप में मैं अपने व्यू कंट्रोलर में didRotateFromInterfaceOrientation: विधि को कार्यान्वित करके इसे दृश्य के अद्यतन फ्रेम का उपयोग करके फिर से किसी भी पॉपओवर को फिर से चलाकर इसे संभालता हूं।

+0

ठीक Github पर जाना चाहिए ..., मैं मैं क्या होगा है लगता है कि तब करने के लिए। नए बटन xy को एनिमेट करना अच्छा लगेगा। धन्यवाद। – mkral

+0

'willRotateToInterfaceOrientation' इस मामले को संभालने के लिए बेहतर परिणाम देता है। –

0

इसका मेरा समाधान @ rmaddy पर सामान्यीकृत भिन्नता है। यह थोड़ा जटिल है, लेकिन यदि आप रोटेशन के लिए कॉलबैक प्राप्त करने के लिए एक सामान्य समाधान चाहते हैं, तो इससे मदद मिल सकती है। मैं एक मुख्य कंटेनर दृश्य नियंत्रक है जिसमें मैं लागू (यदि आप चाहते हैं, UINavigationController का एक उपवर्ग के रूप में इस के बारे में सोच):

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
{ 
    [[SMRotation session] viewControllerWillRotate]; 
} 

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation; 
{ 
    [[SMRotation session] viewControllerDidRotate]; 
} 

कक्षाएं जहां मैं इसे की जरूरत है (आम तौर पर गैर दृश्य नियंत्रक वर्ग) में, मैं कॉलबैक पंजीकृत करें। जैसे,

[[SMRotation session].willRotate addTarget:popTip withSelector:@selector(willRotateHelp)]; 
[[SMRotation session].didRotate addTarget:popTip withSelector:@selector(didRotateHelp)]; 

SMRotation वर्ग इस प्रकार है:

// 
// SMRotation.h 
// Petunia 
// 
// Created by Christopher Prince on 5/10/15. 
// Copyright (c) 2015 Spastic Muffin, LLC. All rights reserved. 
// 

// The reason for this class is because I don't, in general, appear to be able to get willRotate notifications from iOS. UIDevice only seems to support didRotate notifications. 

#import <Foundation/Foundation.h> 
#import "NSObject+TargetsAndSelectors.h" 

@interface SMRotation : NSObject 

+ (instancetype) session; 

// Call these back from the same named methods in your main view controller. 
- (void) viewControllerWillRotate; 
- (void) viewControllerDidRotate; 

// Use these in other classes to get rotation callbacks. There are no parameters passed to the callbacks. 
@property (nonatomic, strong, readonly) NSObject<TargetsAndSelectors> *willRotate; 
@property (nonatomic, strong, readonly) NSObject<TargetsAndSelectors> *didRotate; 

@end 

और

// 
// SMRotation.m 
// Petunia 
// 
// Created by Christopher Prince on 5/10/15. 
// Copyright (c) 2015 Spastic Muffin, LLC. All rights reserved. 
// 

#import "SMRotation.h" 

@interface SMRotation() 
@property (nonatomic, strong) NSObject<TargetsAndSelectors> *willRotate; 
@property (nonatomic, strong) NSObject<TargetsAndSelectors> *didRotate; 
@end 

@implementation SMRotation 

+ (instancetype) session; 
{ 
    static SMRotation* s_sharedInstance = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     s_sharedInstance = [self new]; 
     [s_sharedInstance setup]; 
    }); 

    return s_sharedInstance; 
} 

- (void) setup; 
{ 
    self.willRotate = [NSObject new]; 
    [self.willRotate resetTargets]; 
    self.didRotate = [NSObject new]; 
    [self.didRotate resetTargets]; 
} 

- (void) viewControllerWillRotate; 
{ 
    [self.willRotate forEachTargetInCallbacksDo:^(id target, SEL selector, NSMutableDictionary *dict) { 
     [target performVoidReturnSelector:selector]; 
    }]; 
} 

- (void) viewControllerDidRotate; 
{ 
    [self.didRotate forEachTargetInCallbacksDo:^(id target, SEL selector, NSMutableDictionary *dict) { 
     [target performVoidReturnSelector:selector]; 
    }]; 
} 

@end 

TargetsAndSelectors श्रेणी इस प्रकार है के रूप में:

// 
// NSObject+TargetsAndSelectors.h 
// Petunia 
// 
// Created by Christopher Prince on 5/11/15. 
// Copyright (c) 2015 Spastic Muffin, LLC. All rights reserved. 
// 

#import <Foundation/Foundation.h> 

// Allow an object to have a collection of target's, and selectors that can be called as needed. 

@protocol TargetsAndSelectors <NSObject> 

// The only reason I have made all of these optional is to avoid the compiler complaining. I'm using this protocol just to document the fact that I'm making these methods available (through the NSObject (TargetsAndSelectors) category) in a particular class. 
@optional 

// Clear all target/selector's. This method must be called *before* any call to addTarget or to other methods of this category, for a particular instance. 
- (void) resetTargets; 

/** 
* Add/remove a callback. 
* 
* @param target Target object. 
* @param selector Method to call on the target object. 
* 
* @return Dictionary that was just added to the callbacks property for this target and selector. 
*/ 
- (NSMutableDictionary *) addTarget: (id) target withSelector: (SEL) selector; 
- (void) removeTarget: (id) target withSelector: (SEL) selector; 

/** 
* Convenience method to enable calling each of the callbacks in sequence. 
*/ 
- (void) forEachTargetInCallbacksDo: (void (^)(id target, SEL selector, NSMutableDictionary *dict)) block; 

// Elements are NSMutableDictionary's, with keys: 
// Value of this is a target (id) embedded in a WeakRef object, so that if the target is deallocated, we don't retain a reference that object. 
#define TARGETS_KEY_WEAK_TARGET @"weakTarget" 
// Value of this is formatted as an NSString 
#define TARGETS_KEY_SELECTOR @"selector" 
@property (nonatomic, strong, readonly) NSArray *callbacks; 

@end 

@interface NSObject (TargetsAndSelectors)<TargetsAndSelectors> 
@end 

और

012,351,
// 
// NSObject+TargetsAndSelectors.m 
// Petunia 
// 
// Created by Christopher Prince on 5/11/15. 
// Copyright (c) 2015 Spastic Muffin, LLC. All rights reserved. 
// 

#import "NSObject+TargetsAndSelectors.h" 
#import <objc/runtime.h> 
#import "WeakRef.h" 

@implementation NSObject (TargetsAndSelectors) 

static char kCallbacksKey; 

- (void) setCallbacks:(NSArray *)callbacks 
{ 
    objc_setAssociatedObject(self, &kCallbacksKey, callbacks, OBJC_ASSOCIATION_RETAIN); 
} 

- (NSArray *) callbacks 
{ 
    NSArray *theCallbacks = (NSArray *) objc_getAssociatedObject(self, &kCallbacksKey); 
    return theCallbacks; 
} 

- (void) resetTargets 
{ 
    self.callbacks = [NSMutableArray new]; 
} 

- (NSMutableArray *) mutableCallbacks 
{ 
    NSMutableArray *mutableCallbacks = (NSMutableArray *) self.callbacks; 
    return mutableCallbacks; 
} 

- (NSMutableDictionary *) addTarget: (id) target withSelector: (SEL) selector; 
{ 
    WeakRef *weakTarget = [WeakRef toObj:target]; 

    NSMutableDictionary *dict = [@{TARGETS_KEY_WEAK_TARGET: weakTarget, 
            TARGETS_KEY_SELECTOR: NSStringFromSelector(selector)} mutableCopy]; 
    [[self mutableCallbacks] addObject:dict]; 
    return dict; 
} 

- (void) removeTarget: (id) target withSelector: (SEL) selector; 
{ 
    NSString *stringSelector = NSStringFromSelector(selector); 
    NSDictionary *dictToRemove = nil; 

    for (NSDictionary *dict in [self mutableCallbacks]) { 
     NSString *dictSelectorString = dict[TARGETS_KEY_SELECTOR]; 
     WeakRef *weakTarget = dict[TARGETS_KEY_WEAK_TARGET]; 
     if (weakTarget.obj == target && [dictSelectorString isEqualToString:stringSelector]) { 
      dictToRemove = dict; 
      break; 
     } 
    } 

    if (dictToRemove) { 
     [[self mutableCallbacks] removeObject:dictToRemove]; 
    } 
} 

- (void) forEachTargetInCallbacksDo: (void (^)(id target, SEL selector, NSMutableDictionary *dict)) block; 
{ 
    // 5/10/15; Making a copy of the callbacks array in case one of the callbacks calls removeTarget above. 
    NSArray *copyOfCallbacks = [self.callbacks copy]; 

    for (NSMutableDictionary *dict in copyOfCallbacks) { 
     NSString *dictSelectorString = dict[TARGETS_KEY_SELECTOR]; 
     SEL selector = NSSelectorFromString(dictSelectorString); 

     WeakRef *weakTarget = dict[TARGETS_KEY_WEAK_TARGET]; 

     // Going to just skip by any target that is nil, i.e., has been deallocated. A better idea would be to remove that target from the array... 
     if (weakTarget.obj) { 
      block(weakTarget.obj, selector, dict); 
     } 
    } 
} 

@end 

अंत में, WeakRef है:

// 
// WeakRef.h 
// Petunia 
// 
// Created by Christopher Prince on 9/1/14. 
// Copyright (c) 2014 Spastic Muffin, LLC. All rights reserved. 
// 

#import <Foundation/Foundation.h> 

@interface WeakRef : NSObject 

+ (instancetype) toObj: (id) obj; 
+ (id) from: (WeakRef *) weakRef; 

@property (nonatomic, weak) id obj; 

@end 

और

// 
// WeakRef.m 
// Petunia 
// 
// Created by Christopher Prince on 9/1/14. 
// Copyright (c) 2014 Spastic Muffin, LLC. All rights reserved. 
// 

#import "WeakRef.h" 

@implementation WeakRef 

+ (instancetype) toObj: (id) obj; 
{ 
    WeakRef *result = [WeakRef new]; 
    result.obj = obj; 
    return result; 
} 

+ (id) from: (WeakRef *) weakRef; 
{ 
    return weakRef.obj; 
} 

@end 

इस में से कुछ लगता

संबंधित मुद्दे