我一直在尋找如何做,在iOS6的一個UIPanGestureRecognizer東西,看着頭文件UIPanGestureRecognizer.h的一部分:爲什麼iOS頭文件中列出了私人?屬性?
NS_CLASS_AVAILABLE_IOS(3_2) @interface UIPanGestureRecognizer : UIGestureRecognizer {
@package
CGPoint _firstScreenLocation;
CGPoint _lastScreenLocation;
NSTimeInterval _lastTouchTime;
id _velocitySample;
id _previousVelocitySample;
NSMutableArray *_touches;
NSUInteger _lastTouchCount;
NSUInteger _minimumNumberOfTouches;
NSUInteger _maximumNumberOfTouches;
CGFloat _hysteresis;
CGPoint _lastUnadjustedScreenLocation;
unsigned int _failsPastMaxTouches:1;
unsigned int _canPanHorizontally:1;
unsigned int _canPanVertically:1;
unsigned int _ignoresStationaryTouches:1;
}
@property (nonatomic) NSUInteger minimumNumberOfTouches; // default is 1. the minimum number of touches required to match
@property (nonatomic) NSUInteger maximumNumberOfTouches; // default is UINT_MAX. the maximum number of touches that can be down
- (CGPoint)translationInView:(UIView *)view; // translation in the coordinate system of the specified view
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view;
- (CGPoint)velocityInView:(UIView *)view; // velocity of the pan in pixels/second in the coordinate system of the specified view
@end
我一直在尋找做一些與
CGPoint _firstScreenLocation;
這不是@property,所以它是私人的。
我的問題是:爲什麼我們能夠看到這些私人物品?鑑於它們是「私人」的,它們如何被使用?
我想也許這是在情況下,我們要繼承的對象,所以我想這樣做如下:
#import <UIKit/UIGestureRecognizerSubclass.h>
@interface MyPanGesture : UIPanGestureRecognizer
- (CGPoint) firstLocation;
@end
@implementation MyPanGesture
- (CGPoint) firstLocation
{
return self->_firstScreenLocation;
}
@end
但這構建失敗,一個鏈接錯誤:
未定義的符號對於架構armv7s: 「_OBJC_IVAR _ $ _ UIPanGestureRecognizer._firstScreenLocation」,從引用: - [MyPanGesture firstLocation]在Gesture.o LD:符號(多個)未找到架構armv7s 鐺:錯誤:連接器命令,退出代碼1失敗(使用-v看到調用)
任何人都可以幫助這個困惑的個人嗎?
這些都不是私人性質。它們是實例變量,它們被標記爲「包」範圍。 – rmaddy